• Home
Name Date Size #Lines LOC

..--

escompat/22-Oct-2025-37,81234,078

native/22-Oct-2025-6,5434,655

std/22-Oct-2025-48,70743,643

BUILD.gnD22-Oct-20252.4 KiB7971

README.mdD22-Oct-20256.7 KiB185121

arktsconfig.jsonD22-Oct-2025314 1717

package_stdlib.shD22-Oct-2025871 3213

README.md

1# Style guide
2
3## Spacing
4Remove all trailing whitespaces
5
6File must end with a **single** empty line
7
8In type annotations don't place a space before colon and place single after, like `let x: number | null = null`
9
10Always use block statement within braces (`{}`) after control structures `if`, `while`, `else`. The only exception is `if` after `else`, where braces must be omitted
11
12Always place space between open parenthesis and control structures such as `if`, `while`. Place space between closing parenthesis and open brace in them as well
13
14Always place spaces between operators and operands, example: `a * b + c`
15
16Always be consistent with semicolons (`;`) after statements before line breaks in a single file: either use them always or never. Each statement must be on a separate line
17
18Minimize redundant parenthesis around non bitwise operators. `&&`, `||` and `as` are not exceptions
19
20Always indent statements with 4 spaces within block statement (`{}`) that takes more than one line including braces. Place open brace `{` on the last line of declaring construct, without newline beforehand, but with one after. Place closing brace `}` on a new line. If block statement is empty or consists of a single short line, newlines can be omitted. Single line statement must be separated from braces with a single space from each side. Examples:
21```ts
22if (status == 200) { return true; }
23if (status == 404) {
24	this.getEnvironment().getLogger().debug("...");
25}
26```
27
28Place `else` on the line of `if`'s closing brace `}`, if then clause wasn't a one-liner. And don't embrace this if into a block statement. Examples:
29```ts
30if (ok) { console.log('123') }
31else { console.log('345') }
32if (ok) {
33	// ...
34} else if (ok1) {
35	// ...
36} else {
37	// ...
38}
39```
40
41Empty braces for single-block constructs must be placed on the same line. Example:
42```ts
43function nop(): void {}
44```
45
46Braces must be written in same style for multi-block statements. Examples:
47```ts
48if (ok) { /* ... */ }
49else if (ok) { /* ... */ }
50else { /* ... */ }
51// ^ valid formatting
52
53try {
54    // ...
55} catch (e) {} // <- invalid
56
57if (ok) { fn() }
58else { // <- invalid
59    // ...
60}
61```
62
63### Vertical spaces
64
65Don't use vertical spaces longer than two lines in declarations and longer than one line in code. Declare fields without getters and setters without vertical space between them if they belong to same logical group, or with one to emphasize that they belong to different. Use single vertical space between all methods, and optionally double between their groups. Examples:
66
67```ts
68class Foo {
69    private a1: int;
70    private a2: int;
71
72    private b1: number;
73
74    constructor() {}
75
76    constructor(a1: int) {
77        this.a1 = a1
78    }
79
80
81    function foo(): void {}
82
83    function fooDeprecated(): void {}
84}
85```
86
87
88## Naming
89Name types in camel case, starting with and upper case later, like `VeryLongTypeName`
90
91Name packages, properties and methods in camel case, like `myMethod`. Write entire abbreviation in single case according to rules, like `xmlParser()` or `getXMLParser()`
92
93Name global constants in upper snake case, like `NOT_USED`. This rule also applies to `enum` members
94
95Don't use prefixes or suffixes, including `_`, "Hungarian notation" and others. Also don't use `_` itself as an identifier
96
97## Declarations
98
99### Local variables
100Prefer to omit type annotations
101
102Always start with `const` and promote to `let` only if needed
103
104Avoid variable shadowing
105
106### Class members
107Don't omit `public` and `override`
108
109Prefer most secure applicable visibility: `public` < `protected` < `internal` < `private`
110
111## Exception handling
112
113If "exceptional" control path is "expected", as if file is absent on opening, use `Exception`s. Otherwise, if it is a consequence of a bug, such as invalid argument, use `Error`s
114
115Minimize amount of statements within all blocks of `try`-`catch`-`finally`
116
117Don't `return` from `finally`
118
119Don't annotate `main` with `throws`
120
121## Comments
122For documentation use doc comments, that start with `/**` instead of `/*` and don't use this notation for regular comments
123
124For commenting out parts of code, don't use spaces after `//` and do for text comments. Example:
125```ts
126// TODO: commented out until #... is fixed
127//if (...) {
128//    someMethod1();
129//    someMethod2();
130//}
131```
132
133Prefer using types and identifiers over comments
134
135## `switch` statement
136Always add `default` case if `switch` doesn't cover all alternatives. Place `assert false` if necessary
137
138Mark fallthrough cases with comment `// fallthrough`
139
140## Code developing
141Stdlib has two file types. The first one is editable files that can be modified directly.
142The second type is generated files (starts with `// NOTE: autogenerated file`). They can't be modified directly. You should edit corresponding template. Templates are stored [here](../templates/stdlib/).
143
144## Templates
145* [TypedArray.ets.j2](../templates/stdlib/typedArray.ets.j2) -> [TypedArray.ets](escompat/TypedArrays.ets)
146
147* [TypedUArray.ets.j2](../templates/stdlib/typedUArray.ets.j2) -> [TypedUArray.ets](escompat/TypedUArrays.ets)
148
149* [Array_escompat.erb](../templates/stdlib/Array_escompat.erb) -> [Array.ets](escompat/Array.ets)
150
151* [Array_common.erb](../templates/stdlib/Array_common.erb) -> [BuiltinArray.ets](std/core/BuiltinArray.ets) and [Array.ets](escompat/Array.ets)
152
153* [Array_builtin.erb](../templates/stdlib/Array_builtin.erb) -> [BuiltinArray.ets](std/core/BuiltinArray.ets)
154
155* [Array_builtin_algorithms.ets.j2](../templates/stdlib/Array_builtin_algorithms.ets.j2) -> [BuiltinArrayAlgorithms.ets](std/core/BuiltinArrayAlgorithms.ets)
156
157* [Array_builtin_sort.ets.j2](../templates/stdlib/Array_builtin_sort.ets.j2) -> [BuiltinArraySort.ets](std/core/BuiltinArraySort.ets)
158
159* [Function.ets.j2](../templates/stdlib/Function.ets.j2) -> [Functions.ets](escompat/Functions.ets)
160
161* [Tuple.ets.j2](../templates/stdlib/Tuple.ets.j2) -> [Tuple.ets](std/core/Tuple.ets)
162
163* [DataView.ets.j2](../templates/stdlib/DataView.ets.j2) -> [DataView.ets](escompat/DataView.ets)
164
165* [InteropTransferHelper.ets.j2](../templates/stdlib/InteropTransferHelper.ets.j2) -> [DataView.ets](std/interop/js/InteropTransferHelper.ets)
166
167Jinja2 templates guide https://jinja.palletsprojects.com/en/3.1.x/templates/
168
169ERB templates guide https://github.com/ruby/erb/blob/master/README.md
170
171
172## Code generator
173When templates modification are done. You should use
174[generation script](../templates/stdlib/genlib.sh) to regenerate stdlib files.
175
176```bash
177export PROJECT=/path/to/static_core
178sudo chmod +x $PROJECT/plugins/ets/templates/stdlib/genlib.sh
179$PROJECT/plugins/ets/templates/stdlib/genlib.sh
180```
181
182Template changes and generated files should be commited at the same time. Generated files are needed to make review easier.
183During build `generation script` creates files in temporary directory and compares it with existing stdlib files. The build stops if the difference is found.
184
185