|
1 | | -/* global module */ |
2 | | - |
3 | | -module.exports = { |
4 | | - root: true, |
5 | | - parser: "@typescript-eslint/parser", |
6 | | - plugins: [ |
7 | | - "@typescript-eslint", |
8 | | - ], |
9 | | - extends: [ |
10 | | - "eslint:recommended", |
11 | | - "plugin:@typescript-eslint/eslint-recommended", |
12 | | - "plugin:@typescript-eslint/recommended", |
13 | | - ], |
14 | | - parserOptions: { |
15 | | - ecmaVersion: 2020, |
16 | | - sourceType: "module", |
17 | | - ecmaFeatures: {} |
18 | | - }, |
19 | | - globals: { |
20 | | - "globalThis": "readonly", |
21 | | - "BigInt64Array": "readonly", |
22 | | - "BigUint64Array": "readonly", |
23 | | - "WebAssembly": "readonly", |
24 | | - "FinalizationRegistry": "readonly", |
25 | | - "fetch": "readonly", |
26 | | - "URL": "readonly", |
27 | | - "console": "readonly" |
28 | | - }, |
29 | | - |
30 | | - // === General rules ========================================================= |
31 | | - |
32 | | - rules: { |
33 | | - // Omitted semicolons are hugely popular, yet within the compiler it makes |
34 | | - // sense to be better safe than sorry. |
35 | | - "semi": "error", |
36 | | - |
37 | | - // Our code bases uses 2 spaces for indentation, and we enforce it here so |
38 | | - // files don't mix spaces, tabs or different indentation levels. |
39 | | - "indent": ["error", 2, { |
40 | | - "SwitchCase": 1, |
41 | | - "VariableDeclarator": "first", |
42 | | - "offsetTernaryExpressions": true, |
43 | | - "ignoredNodes": [ // FIXME: something's odd here |
44 | | - "ConditionalExpression > *", |
45 | | - "ConditionalExpression > * > *", |
46 | | - "ConditionalExpression > * > * > *" |
47 | | - ] |
48 | | - }], |
49 | | - |
50 | | - // This is mostly visual style, making comments look uniform. |
51 | | - "spaced-comment": ["error", "always", { |
52 | | - "markers": ["/"], // triple-slash |
53 | | - "exceptions": ["/"] // all slashes |
54 | | - }], |
55 | | - |
56 | | - // This tends to be annoying as it encourages developers to make everything |
57 | | - // that is never reassigned a 'const', sometimes semantically incorrect so, |
58 | | - // typically leading to huge diffs in follow-up PRs modifying affected code. |
59 | | - "prefer-const": "off", |
60 | | - |
61 | | - // It is perfectly fine to declare top-level variables with `var`, yet this |
62 | | - // rule doesn't provide configuration options that would help. |
63 | | - "no-var": "off", |
64 | | - |
65 | | - // Quite often, dealing with multiple related cases at once or otherwise |
66 | | - // falling through is exactly the point of using a switch. |
67 | | - "no-fallthrough": "off", |
68 | | - "no-useless-assignment": "off", |
69 | | - "no-unassigned-vars": "off", |
70 | | - "preserve-caught-error": "off", |
71 | | - |
72 | | - // Typical false-positives here are `do { ... } while (true)` statements or |
73 | | - // similar, but the only option provided here is not checking any loops. |
74 | | - "no-constant-condition": ["error", { checkLoops: false }], |
75 | | - |
76 | | - // Functions are nested in blocks occasionally, and there haven't been any |
77 | | - // problems with this so far, so turning the check off. |
78 | | - "no-inner-declarations": "off", |
79 | | - |
80 | | - // Quite common in scenarios where an iteration starts at `current = this`. |
81 | | - "@typescript-eslint/no-this-alias": "off", |
82 | | - |
83 | | - // Interferes with tests and 64-bit literals |
84 | | - "@typescript-eslint/no-loss-of-precision": "off", |
85 | | - |
86 | | - // Disabled here, but enabled again for JavaScript files. |
87 | | - "no-unused-vars": "off", |
88 | | - |
89 | | - // Disabled here, but enabled again for TypeScript files. |
90 | | - "@typescript-eslint/no-unused-vars": "off" |
91 | | - }, |
92 | | - overrides: [ |
93 | | - |
94 | | - // === JavaScript rules ==================================================== |
95 | | - |
96 | | - { |
97 | | - env: { |
98 | | - "browser": true, |
99 | | - "amd": true, |
100 | | - "node": true, |
101 | | - "es6": true |
102 | | - }, |
103 | | - files: [ |
104 | | - "**/*.js", |
105 | | - "bin/*" |
106 | | - ], |
107 | | - rules: { |
108 | | - // We are testing both ESM and UMD, so don't limit us. |
109 | | - "@typescript-eslint/no-var-requires": "off", |
110 | | - |
111 | | - // This rule does not behave well in JS files. |
112 | | - "@typescript-eslint/explicit-module-boundary-types": "off", |
113 | | - |
114 | | - // Enforcing to remove function parameters on stubs makes code less |
115 | | - // maintainable, so we instead allow unused function parameters. |
116 | | - "no-unused-vars": [ |
117 | | - "warn", { |
118 | | - "vars": "local", |
119 | | - "args": "none", |
120 | | - "ignoreRestSiblings": false |
121 | | - } |
122 | | - ], |
123 | | - |
124 | | - "@typescript-eslint/no-loss-of-precision": "error", |
125 | | - } |
126 | | - }, |
127 | | - |
128 | | - // === TypeScript rules ==================================================== |
129 | | - |
130 | | - { |
131 | | - files: [ |
132 | | - "**/*.ts" |
133 | | - ], |
134 | | - rules: { |
135 | | - // Enforcing to remove function parameters on stubs makes code less |
136 | | - // maintainable, so we instead allow unused function parameters. |
137 | | - "@typescript-eslint/no-unused-vars": [ |
138 | | - "warn", { |
139 | | - "vars": "local", |
140 | | - "varsIgnorePattern": "^[A-Z](?:From|To)?$", // ignore type params |
141 | | - "args": "none", |
142 | | - "ignoreRestSiblings": false |
143 | | - } |
144 | | - ] |
145 | | - } |
146 | | - }, |
147 | | - |
148 | | - // === AssemblyScript rules (extends TypeScript rules) ===================== |
149 | | - |
150 | | - { |
151 | | - files: [ |
152 | | - "**/assembly/**/*.ts", |
153 | | - "src/**/*.ts", |
154 | | - "lib/parse/src/**/*.ts" |
155 | | - ], |
156 | | - rules: { |
157 | | - // Namespaces are quite useful in AssemblyScript |
158 | | - "@typescript-eslint/no-namespace": "off", |
159 | | - |
160 | | - // There is actually codegen difference here |
161 | | - "@typescript-eslint/no-array-constructor": "off", |
162 | | - |
163 | | - // Sometimes it can't be avoided to add a @ts-ignore |
164 | | - "@typescript-eslint/ban-ts-comment": "off", |
165 | | - |
166 | | - // Utilized to achieve portability in some cases |
167 | | - "@typescript-eslint/no-non-null-assertion": "off", |
168 | | - } |
169 | | - }, |
170 | | - |
171 | | - // === Compiler rules (extends AssemblyScript rules) ======================= |
172 | | - |
173 | | - { |
174 | | - files: [ |
175 | | - "src/**/*.ts", |
176 | | - "std/assembly/**/*.ts" |
177 | | - ], |
178 | | - rules: { |
179 | | - // There is an actual codegen difference here - TODO: revisit |
180 | | - "no-cond-assign": "off", |
181 | | - |
182 | | - // Not all types can be omitted in AS yet - TODO: revisit |
183 | | - "@typescript-eslint/no-inferrable-types": "off", |
184 | | - |
185 | | - // Used rarely to reference internals that are not user-visible |
186 | | - "@typescript-eslint/triple-slash-reference": "off", |
187 | | - |
188 | | - // The compiler has its own `Function` class for example |
189 | | - "no-shadow-restricted-names": "off", |
190 | | - "@typescript-eslint/ban-types": "off" |
191 | | - } |
192 | | - }, |
193 | | - |
194 | | - // === Standard Library rules (extends AssemblyScript rules) =============== |
195 | | - |
196 | | - { |
197 | | - files: [ |
198 | | - "std/assembly/**/*.ts" |
199 | | - ], |
200 | | - rules: { |
201 | | - // We are implementing with --noLib, so we shadow all the time |
202 | | - "no-shadow-restricted-names": "off", |
203 | | - |
204 | | - // Similarly, sometimes we need the return type to be String, not string |
205 | | - "@typescript-eslint/ban-types": "off" |
206 | | - } |
207 | | - }, |
208 | | - |
209 | | - // === Standard Definition rules (extends TypeScript rules) ================ |
210 | | - |
211 | | - { |
212 | | - files: [ |
213 | | - "std/**/*.d.ts" |
214 | | - ], |
215 | | - rules: { |
216 | | - // Often required to achieve compatibility with TypeScript |
217 | | - "@typescript-eslint/no-explicit-any": "off", |
218 | | - |
219 | | - // Interfaces can be stubs here, i.e. not yet fully implemented |
220 | | - "@typescript-eslint/no-empty-interface": "off", |
221 | | - |
222 | | - // Definitions make use of `object` to model rather unusual constraints |
223 | | - "@typescript-eslint/ban-types": "off" |
224 | | - } |
225 | | - }, |
226 | | - |
227 | | - // === Compiler Definition rules (extends TypeScript rules) ================ |
228 | | - |
229 | | - { |
230 | | - files: [ |
231 | | - "./dist/*.d.ts" |
232 | | - ], |
233 | | - rules: { |
234 | | - // Our definitions are complicated, and all attempts to describe them |
235 | | - // as modules have failed so far. As such, we re-export namespaces. |
236 | | - "@typescript-eslint/no-namespace": "off", |
237 | | - "@typescript-eslint/triple-slash-reference": "off" |
238 | | - } |
239 | | - }, |
240 | | - |
241 | | - // === Test rules (extends TypeScript rules) =============================== |
242 | | - |
243 | | - { |
244 | | - files: [ |
245 | | - "./tests/compiler/**/*.ts", |
246 | | - "./lib/loader/tests/assembly/**/*.ts" |
247 | | - ], |
248 | | - rules: { |
249 | | - // Tests typically include unusual code patterns on purpose. This is |
250 | | - // very likely not an extensive list, but covers what's there so far. |
251 | | - "no-empty": "off", |
252 | | - "no-cond-assign": "off", |
253 | | - "no-compare-neg-zero": "off", |
254 | | - "no-inner-declarations": "off", |
255 | | - "no-constant-condition": "off", |
256 | | - "use-isnan": "off", |
257 | | - "@typescript-eslint/no-namespace": "off", |
258 | | - "@typescript-eslint/no-unused-vars": "off", |
259 | | - "@typescript-eslint/no-empty-function": "off", |
260 | | - "@typescript-eslint/no-non-null-assertion": "off", |
261 | | - "@typescript-eslint/no-extra-semi": "off", |
262 | | - "@typescript-eslint/no-inferrable-types": "off", |
263 | | - "@typescript-eslint/ban-types": "off", |
264 | | - "@typescript-eslint/triple-slash-reference": "off", |
265 | | - "@typescript-eslint/ban-ts-comment": "off", |
266 | | - "@typescript-eslint/no-extra-non-null-assertion": "off", |
267 | | - "@typescript-eslint/no-empty-interface": "off" |
268 | | - } |
269 | | - }, |
270 | | - ] |
271 | | -}; |
0 commit comments