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 | 2953fa1 | 2024-03-18 14:17:15 +0000 | [diff] [blame] | 30 | // Formatting handled by prettier |
| 31 | "indent": "off", |
| 32 | 'max-len': "off", |
| 33 | "operator-linebreak": "off", |
| 34 | "quotes": "off", |
| 35 | "brace-style": "off", |
| 36 | "space-before-function-paren": "off", |
| 37 | "generator-star-spacing": "off", |
| 38 | "semi-spacing": "off", |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 39 | |
Steve Golton | 7a4efa5 | 2024-01-25 09:18:45 +0000 | [diff] [blame] | 40 | // 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] | 41 | // if (foo) { // insightful comment |
| 42 | // with two spaces between the slash and the brace. Turn |
| 43 | // ignoreEOLComments on to allow that. We still want |
| 44 | // no-multi-spaces turned on in general as it fixes issues like: |
| 45 | // if (a === b) |
| 46 | 'no-multi-spaces': ['error', {ignoreEOLComments: true}], |
| 47 | |
| 48 | // Default no-unused-vars doesn't understand TypeScript enums. See: |
| 49 | // https://github.com/typescript-eslint/typescript-eslint/issues/2621 |
| 50 | 'no-unused-vars': 'off', |
| 51 | '@typescript-eslint/no-unused-vars': |
Steve Golton | 9ae7558 | 2023-01-26 18:48:16 +0000 | [diff] [blame] | 52 | ['error', {'argsIgnorePattern': '^_.*', 'varsIgnorePattern': '^_.*'}], |
Hector Dearman | 1518b6d | 2022-06-05 11:58:54 +0100 | [diff] [blame] | 53 | |
| 54 | // new Array() is banned (use [] instead) but new Array<Foo>() is |
| 55 | // allowed since it can be clearer to put the type by the |
| 56 | // construtor. |
| 57 | 'no-array-constructor': 'off', |
| 58 | '@typescript-eslint/no-array-constructor': ['error'], |
Hector Dearman | c29629f | 2022-06-05 12:59:39 +0100 | [diff] [blame] | 59 | |
Tuchila Octavian | c80e796 | 2022-08-25 18:06:14 +0100 | [diff] [blame] | 60 | // Rest parameters are not equivalent to 'arguments'. |
| 61 | // Rest parameters are arrays: https://developer.mozilla.org/en-US/docs/Web/ |
| 62 | // JavaScript/Reference/Functions/rest_parameters |
| 63 | // 'arguments' are objects: https://developer.mozilla.org/en-US/docs/Web/ |
| 64 | // JavaScript/Reference/Functions/arguments |
| 65 | 'prefer-rest-params': 'off', |
| 66 | |
Hector Dearman | c29629f | 2022-06-05 12:59:39 +0100 | [diff] [blame] | 67 | // We have a lot normal functions which are capitalised. |
| 68 | // TODO(hjd): Switch these to be lowercase and remove capIsNew. |
| 69 | // There are also some properties like: foo.factory these should |
| 70 | // stay. |
Hector Dearman | 4404819 | 2022-06-06 09:44:05 +0100 | [diff] [blame] | 71 | 'new-cap': ['error', {'capIsNew': false, 'properties': false}], |
Hector Dearman | 8a0ec98 | 2023-10-30 17:32:49 +0000 | [diff] [blame] | 72 | |
| 73 | // Don't allow new introduction of any it is most always a mistake. |
| 74 | '@typescript-eslint/no-explicit-any': 'error', |
Steve Golton | 13a79de | 2024-01-10 13:23:20 +0000 | [diff] [blame] | 75 | |
| 76 | // Prohibit numbers and strings from being used in boolean expressions. |
| 77 | '@typescript-eslint/strict-boolean-expressions': [ |
| 78 | 'error', |
| 79 | { |
| 80 | // Eventually we probably want to enable all of these, for now this |
| 81 | // tackles numbers and keeps the error count manageable. |
| 82 | allowAny: true, |
| 83 | allowNullableBoolean: true, |
| 84 | allowNullableString: true, |
| 85 | allowNumber: true, |
| 86 | allowString: true, |
| 87 | }, |
| 88 | ], |
Hector Dearman | 4dc1cdc | 2022-05-19 09:05:21 +0100 | [diff] [blame] | 89 | }, |
| 90 | }; |