blob: c5120f4f0d2fbfb0f0b5702323648ce4606b3df9 [file] [log] [blame]
Hector Dearman4dc1cdc2022-05-19 09:05:21 +01001module.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 Golton13a79de2024-01-10 13:23:20 +000014 'project': './tsconfig.json',
Hector Dearman4dc1cdc2022-05-19 09:05:21 +010015 },
16 'plugins': [
17 '@typescript-eslint',
18 ],
19 'rules': {
Hector Dearman1518b6d2022-06-05 11:58:54 +010020 // We don't want to enforce jsdoc everywhere:
Hector Dearman4dc1cdc2022-05-19 09:05:21 +010021 'require-jsdoc': 'off',
Hector Dearman1518b6d2022-06-05 11:58:54 +010022
Steve Goltond9c32312024-01-25 11:58:39 +000023 // Relax jsdoc requirements
24 'valid-jsdoc': ['error', {
25 'requireParamType': false,
26 'requireReturnType': false,
27 'requireReturn': false,
28 }],
29
Steve Golton7a4efa52024-01-25 09:18:45 +000030 // Max line length is 80 with 2 space tabs.
31 // This matches the the old clang-format definition for consistency.
Hector Dearman1518b6d2022-06-05 11:58:54 +010032 'max-len': [
33 'error',
34 {
35 'code': 80,
36 'tabWidth': 2,
37 'ignoreUrls': true,
38 'ignoreTemplateLiterals': true,
39 'ignoreStrings': true,
Hector Dearman44048192022-06-06 09:44:05 +010040 },
Hector Dearman1518b6d2022-06-05 11:58:54 +010041 ],
42
Steve Golton7a4efa52024-01-25 09:18:45 +000043 "indent": ["error", 2],
Hector Dearman1518b6d2022-06-05 11:58:54 +010044
Steve Golton7a4efa52024-01-25 09:18:45 +000045 // clang-format --js used to format EOL comments after (e.g.) an if like:
Hector Dearman1518b6d2022-06-05 11:58:54 +010046 // 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 Golton9ae75582023-01-26 18:48:16 +000057 ['error', {'argsIgnorePattern': '^_.*', 'varsIgnorePattern': '^_.*'}],
Hector Dearman1518b6d2022-06-05 11:58:54 +010058
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 Dearmanc29629f2022-06-05 12:59:39 +010064
Tuchila Octavianc80e7962022-08-25 18:06:14 +010065 // 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 Dearmanc29629f2022-06-05 12:59:39 +010072 // 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 Dearman44048192022-06-06 09:44:05 +010076 'new-cap': ['error', {'capIsNew': false, 'properties': false}],
Hector Dearman8a0ec982023-10-30 17:32:49 +000077
78 // Don't allow new introduction of any it is most always a mistake.
79 '@typescript-eslint/no-explicit-any': 'error',
Steve Golton13a79de2024-01-10 13:23:20 +000080
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 Dearman4dc1cdc2022-05-19 09:05:21 +010094 },
95};