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