Hector Dearman | 4dc1cdc | 2022-05-19 09:05:21 +0100 | [diff] [blame] | 1 | module.exports = { |
| 2 | 'env': { |
| 3 | 'browser': true, |
| 4 | 'es2021': true, |
| 5 | 'node': true, |
| 6 | }, |
| 7 | 'extends': [ |
| 8 | 'google', |
| 9 | ], |
| 10 | 'parser': '@typescript-eslint/parser', |
| 11 | 'parserOptions': { |
| 12 | 'ecmaVersion': 'latest', |
| 13 | 'sourceType': 'module', |
Steve Golton | 13a79de | 2024-01-10 13:23:20 +0000 | [diff] [blame] | 14 | 'project': './tsconfig.json', |
Hector Dearman | 4dc1cdc | 2022-05-19 09:05:21 +0100 | [diff] [blame] | 15 | }, |
| 16 | 'plugins': [ |
| 17 | '@typescript-eslint', |
| 18 | ], |
| 19 | 'rules': { |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 20 | // We don't want to enforce jsdoc everywhere: |
Hector Dearman | 4dc1cdc | 2022-05-19 09:05:21 +0100 | [diff] [blame] | 21 | 'require-jsdoc': 'off', |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 22 | |
Steve Golton | d9c3231 | 2024-01-25 11:58:39 +0000 | [diff] [blame^] | 23 | // Relax jsdoc requirements |
| 24 | 'valid-jsdoc': ['error', { |
| 25 | 'requireParamType': false, |
| 26 | 'requireReturnType': false, |
| 27 | 'requireReturn': false, |
| 28 | }], |
| 29 | |
Steve Golton | 7a4efa5 | 2024-01-25 09:18:45 +0000 | [diff] [blame] | 30 | // Max line length is 80 with 2 space tabs. |
| 31 | // This matches the the old clang-format definition for consistency. |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 32 | 'max-len': [ |
| 33 | 'error', |
| 34 | { |
| 35 | 'code': 80, |
| 36 | 'tabWidth': 2, |
| 37 | 'ignoreUrls': true, |
| 38 | 'ignoreTemplateLiterals': true, |
| 39 | 'ignoreStrings': true, |
Hector Dearman | 4404819 | 2022-06-06 09:44:05 +0100 | [diff] [blame] | 40 | }, |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 41 | ], |
| 42 | |
Steve Golton | 7a4efa5 | 2024-01-25 09:18:45 +0000 | [diff] [blame] | 43 | "indent": ["error", 2], |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 44 | |
Steve Golton | 7a4efa5 | 2024-01-25 09:18:45 +0000 | [diff] [blame] | 45 | // clang-format --js used to format EOL comments after (e.g.) an if like: |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 46 | // if (foo) { // insightful comment |
| 47 | // with two spaces between the slash and the brace. Turn |
| 48 | // ignoreEOLComments on to allow that. We still want |
| 49 | // no-multi-spaces turned on in general as it fixes issues like: |
| 50 | // if (a === b) |
| 51 | 'no-multi-spaces': ['error', {ignoreEOLComments: true}], |
| 52 | |
| 53 | // Default no-unused-vars doesn't understand TypeScript enums. See: |
| 54 | // https://github.com/typescript-eslint/typescript-eslint/issues/2621 |
| 55 | 'no-unused-vars': 'off', |
| 56 | '@typescript-eslint/no-unused-vars': |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 57 | ['error', {'argsIgnorePattern': '^_.*', 'varsIgnorePattern': '^_.*'}], |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 58 | |
| 59 | // new Array() is banned (use [] instead) but new Array<Foo>() is |
| 60 | // allowed since it can be clearer to put the type by the |
| 61 | // construtor. |
| 62 | 'no-array-constructor': 'off', |
| 63 | '@typescript-eslint/no-array-constructor': ['error'], |
Hector Dearman | c29629f | 2022-06-05 12:59:39 +0100 | [diff] [blame] | 64 | |
Tuchila Octavian | c80e796 | 2022-08-25 18:06:14 +0100 | [diff] [blame] | 65 | // Rest parameters are not equivalent to 'arguments'. |
| 66 | // Rest parameters are arrays: https://developer.mozilla.org/en-US/docs/Web/ |
| 67 | // JavaScript/Reference/Functions/rest_parameters |
| 68 | // 'arguments' are objects: https://developer.mozilla.org/en-US/docs/Web/ |
| 69 | // JavaScript/Reference/Functions/arguments |
| 70 | 'prefer-rest-params': 'off', |
| 71 | |
Hector Dearman | c29629f | 2022-06-05 12:59:39 +0100 | [diff] [blame] | 72 | // We have a lot normal functions which are capitalised. |
| 73 | // TODO(hjd): Switch these to be lowercase and remove capIsNew. |
| 74 | // There are also some properties like: foo.factory these should |
| 75 | // stay. |
Hector Dearman | 4404819 | 2022-06-06 09:44:05 +0100 | [diff] [blame] | 76 | 'new-cap': ['error', {'capIsNew': false, 'properties': false}], |
Hector Dearman | 8a0ec98 | 2023-10-30 17:32:49 +0000 | [diff] [blame] | 77 | |
| 78 | // Don't allow new introduction of any it is most always a mistake. |
| 79 | '@typescript-eslint/no-explicit-any': 'error', |
Steve Golton | 13a79de | 2024-01-10 13:23:20 +0000 | [diff] [blame] | 80 | |
| 81 | // Prohibit numbers and strings from being used in boolean expressions. |
| 82 | '@typescript-eslint/strict-boolean-expressions': [ |
| 83 | 'error', |
| 84 | { |
| 85 | // Eventually we probably want to enable all of these, for now this |
| 86 | // tackles numbers and keeps the error count manageable. |
| 87 | allowAny: true, |
| 88 | allowNullableBoolean: true, |
| 89 | allowNullableString: true, |
| 90 | allowNumber: true, |
| 91 | allowString: true, |
| 92 | }, |
| 93 | ], |
Hector Dearman | 4dc1cdc | 2022-05-19 09:05:21 +0100 | [diff] [blame] | 94 | }, |
| 95 | }; |