blob: 9203e70496738942776424f6d97e9d20de07abd5 [file] [log] [blame]
Jack Franklinaba88002020-11-26 16:23:051// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Jack Franklindf0e9312022-12-05 10:29:525// clang-format off
6
Tim van der Lipped6c33c42020-03-10 16:57:227const path = require('path');
Jack Franklinaba88002020-11-26 16:23:058const rulesDirPlugin = require('eslint-plugin-rulesdir');
Tim van der Lipped6c33c42020-03-10 16:57:229rulesDirPlugin.RULES_DIR = path.join(__dirname, 'scripts', 'eslint_rules', 'lib');
10
Blink Reformat4c46d092018-04-07 15:32:3711module.exports = {
Tim van der Lippe1d6e57a2019-09-30 11:55:3412 'root': true,
Blink Reformat4c46d092018-04-07 15:32:3713
Tim van der Lippe1d6e57a2019-09-30 11:55:3414 'env': {'browser': true, 'es6': true},
Blink Reformat4c46d092018-04-07 15:32:3715
Tim van der Lippe399a9562020-01-16 10:53:2816 'parser': '@typescript-eslint/parser',
17
18 'plugins': [
19 '@typescript-eslint',
Jack Franklin8b9aa2f2020-02-12 16:35:1520 'mocha',
Tim van der Lipped6c33c42020-03-10 16:57:2221 'rulesdir',
Tim van der Lippe298b8cc2020-04-03 11:55:1022 'import',
Jack Franklinfd72c072022-12-21 11:45:0123 'jsdoc',
Tim van der Lippe399a9562020-01-16 10:53:2824 ],
25
Tim van der Lippe1d6e57a2019-09-30 11:55:3426 'parserOptions': {'ecmaVersion': 9, 'sourceType': 'module'},
Blink Reformat4c46d092018-04-07 15:32:3727
Tim van der Lippe1d6e57a2019-09-30 11:55:3428 /**
Tim van der Lippe406249f2020-12-14 14:59:1029 * ESLint rules
30 *
31 * All available rules: http://eslint.org/docs/rules/
Tim van der Lippe406249f2020-12-14 14:59:1032 */
Tim van der Lippe1d6e57a2019-09-30 11:55:3433 'rules': {
34 /**
Tim van der Lippe406249f2020-12-14 14:59:1035 * Enforced rules
36 */
Blink Reformat4c46d092018-04-07 15:32:3737
Tim van der Lippe1d6e57a2019-09-30 11:55:3438 // syntax preferences
Nikolay Vitkovc62f5c52024-01-17 13:23:3439 'quotes': ['error', 'single', {'avoidEscape': true, 'allowTemplateLiterals': false}],
40 'semi': 'error',
41 'no-extra-semi': 'error',
42 'comma-style': ['error', 'last'],
43 'wrap-iife': ['error', 'inside'],
44 'spaced-comment': ['error', 'always', {'markers': ['*']}],
45 'eqeqeq': 'error',
46 'accessor-pairs': ['error', {'getWithoutSet': false, 'setWithoutGet': false}],
47 'curly': 'error',
48 'new-parens': 'error',
49 'func-call-spacing': 'error',
50 'arrow-parens': ['error', 'as-needed'],
51 'eol-last': 'error',
Blink Reformat4c46d092018-04-07 15:32:3752
Tim van der Lippe1d6e57a2019-09-30 11:55:3453 // anti-patterns
Nikolay Vitkovc62f5c52024-01-17 13:23:3454 'no-caller': 'error',
55 'no-case-declarations': 'error',
56 'no-cond-assign': 'error',
57 'no-console': ['error', {'allow': ['assert', 'context', 'error', 'timeStamp', 'time', 'timeEnd', 'warn']}],
58 'no-debugger': 'error',
59 'no-dupe-keys': 'error',
60 'no-duplicate-case': 'error',
61 'no-else-return': ['error', {'allowElseIf': false}],
62 'no-empty-character-class': 'error',
63 'no-global-assign': 'error',
64 'no-implied-eval': 'error',
65 'no-labels': 'error',
66 'no-multi-str': 'error',
67 'no-new-object': 'error',
68 'no-octal-escape': 'error',
69 'no-self-compare': 'error',
70 'no-shadow-restricted-names': 'error',
71 'no-unreachable': 'error',
72 'no-unsafe-negation': 'error',
73 'no-unused-vars': ['error', {'args': 'none', 'vars': 'local'}],
74 'no-var': 'error',
75 'no-with': 'error',
76 'prefer-const': 'error',
77 'radix': 'error',
78 'valid-typeof': 'error',
79 'no-return-assign': ['error', 'always'],
80 'no-implicit-coercion': 'error',
Blink Reformat4c46d092018-04-07 15:32:3781
Tim van der Lippe1d6e57a2019-09-30 11:55:3482 // es2015 features
Nikolay Vitkovc62f5c52024-01-17 13:23:3483 'require-yield': 'error',
84 'template-curly-spacing': ['error', 'never'],
Blink Reformat4c46d092018-04-07 15:32:3785
Tim van der Lippe1d6e57a2019-09-30 11:55:3486 // file whitespace
Nikolay Vitkovc62f5c52024-01-17 13:23:3487 'no-multiple-empty-lines': ['error', {'max': 1}],
88 'no-mixed-spaces-and-tabs': 'error',
89 'no-trailing-spaces': 'error',
90 'linebreak-style': ['error', 'unix'],
Blink Reformat4c46d092018-04-07 15:32:3791
Tim van der Lippe1d6e57a2019-09-30 11:55:3492 /**
Tim van der Lippe406249f2020-12-14 14:59:1093 * Disabled, aspirational rules
94 */
Blink Reformat4c46d092018-04-07 15:32:3795
Nikolay Vitkovc62f5c52024-01-17 13:23:3496 'indent': ['off', 2, {'SwitchCase': 1, 'CallExpression': {'arguments': 2}, 'MemberExpression': 2}],
Blink Reformat4c46d092018-04-07 15:32:3797
Tim van der Lippe1d6e57a2019-09-30 11:55:3498 // brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions
Nikolay Vitkovc62f5c52024-01-17 13:23:3499 'brace-style': ['off', 'allman', {'allowSingleLine': true}],
Blink Reformat4c46d092018-04-07 15:32:37100
Tim van der Lippe1d6e57a2019-09-30 11:55:34101 // key-spacing is disabled, as some objects use value-aligned spacing, some not.
Nikolay Vitkovc62f5c52024-01-17 13:23:34102 'key-spacing': ['off', {'beforeColon': false, 'afterColon': true, 'align': 'value'}],
Tim van der Lippe1d6e57a2019-09-30 11:55:34103 // quote-props is diabled, as property quoting styles are too varied to enforce.
Nikolay Vitkovc62f5c52024-01-17 13:23:34104 'quote-props': ['off', 'as-needed'],
Blink Reformat4c46d092018-04-07 15:32:37105
Tim van der Lippe1d6e57a2019-09-30 11:55:34106 // no-implicit-globals will prevent accidental globals
Nikolay Vitkovc62f5c52024-01-17 13:23:34107 'no-implicit-globals': 'off',
108 'no-unused-private-class-members': 'error',
Tim van der Lippe399a9562020-01-16 10:53:28109
Jack Franklin264237a2020-07-15 09:02:26110 // forbids interfaces starting with an I prefix.
Paul Lewis839037f2020-07-21 12:25:19111 '@typescript-eslint/naming-convention':
Nikolay Vitkovc62f5c52024-01-17 13:23:34112 ['error', {'selector': 'interface', 'format': ['PascalCase'], 'custom': {'regex': '^I[A-Z]', 'match': false}}],
113 '@typescript-eslint/explicit-member-accessibility': 'off',
Benedikt Meurercfc8cd62024-01-17 10:08:28114 '@typescript-eslint/no-explicit-any': [
115 "error",
116 {
117 "ignoreRestArgs": true
118 }
119 ],
Jack Franklin8b9aa2f2020-02-12 16:35:15120
Tim van der Lippe298b8cc2020-04-03 11:55:10121 // Closure does not properly typecheck default exports
Nikolay Vitkovc62f5c52024-01-17 13:23:34122 'import/no-default-export': 'error',
Tim van der Lippe298b8cc2020-04-03 11:55:10123
Jack Franklin6d9f8772023-07-11 10:55:01124 /**
125 * Catch duplicate import paths. For example this would catch the following example:
126 * import {Foo} from './foo.js'
127 * import * as FooModule from './foo.js'
128 **/
Nikolay Vitkovc62f5c52024-01-17 13:23:34129 'import/no-duplicates': 'error',
Jack Franklin6d9f8772023-07-11 10:55:01130
Jack Franklin02f0dbb2021-03-02 14:10:49131 // Try to spot '// console.log()' left over from debugging
Nikolay Vitkovc62f5c52024-01-17 13:23:34132 'rulesdir/commented_out_console': 'error',
Jack Franklin02f0dbb2021-03-02 14:10:49133
Jack Franklindf0e9312022-12-05 10:29:52134 // Prevent imports being commented out rather than deleted.
Nikolay Vitkovc62f5c52024-01-17 13:23:34135 'rulesdir/commented_out_import': 'error',
Jack Franklindf0e9312022-12-05 10:29:52136
Tim van der Lipped6c33c42020-03-10 16:57:22137 // DevTools specific rules
Nikolay Vitkovc62f5c52024-01-17 13:23:34138 'rulesdir/es_modules_import': 'error',
139 'rulesdir/check_license_header': 'error',
Jack Franklinc8d5dd22022-12-21 14:58:15140 /**
141 * Ensures that JS Doc comments are properly aligned - all the starting
142 * `*` are in the right place.
143 */
Nikolay Vitkovc62f5c52024-01-17 13:23:34144 'jsdoc/check-alignment': 'error',
Tim van der Lippe399a9562020-01-16 10:53:28145 },
146 'overrides': [{
147 'files': ['*.ts'],
Simon Zünd607774a2021-06-16 10:55:53148 'parserOptions': {
149 'allowAutomaticSingleRunInference': true,
Jack Franklin468d7592023-06-02 13:17:33150 'project': path.join(__dirname, 'config', 'typescript', 'tsconfig.eslint.json'),
Simon Zünd607774a2021-06-16 10:55:53151 },
Tim van der Lippe399a9562020-01-16 10:53:28152 'rules': {
Nikolay Vitkovc62f5c52024-01-17 13:23:34153 '@typescript-eslint/explicit-member-accessibility': ['error', {'accessibility': 'no-public'}],
Sigurd Schneider9c075672021-02-03 13:16:39154 'comma-dangle': 'off',
Nikolay Vitkovc62f5c52024-01-17 13:23:34155 '@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
Tim van der Lippe0ebbf492020-12-03 12:13:21156
Jack Franklin95310322020-03-20 14:34:04157 // run just the TypeScript unused-vars rule, else we get duplicate errors
Nikolay Vitkovc62f5c52024-01-17 13:23:34158 'no-unused-vars': 'off',
159 '@typescript-eslint/no-unused-vars': ['error', {'argsIgnorePattern': '^_'}],
Tim van der Lippe0ebbf492020-12-03 12:13:21160 // run just the TypeScript semi rule, else we get duplicate errors
Nikolay Vitkovc62f5c52024-01-17 13:23:34161 'semi': 'off',
162 '@typescript-eslint/semi': 'error',
Sigurd Schneider15761862021-02-04 08:05:36163 '@typescript-eslint/member-delimiter-style': [
164 'error', {
165 'multiline': {'delimiter': 'semi', 'requireLast': true},
166 'singleline': {'delimiter': 'comma', 'requireLast': false},
167 'overrides': {
168 'interface': {
169 'singleline': {'delimiter': 'semi', 'requireLast': false},
170 'multiline': {'delimiter': 'semi', 'requireLast': true}
171 },
172 'typeLiteral': {
173 'singleline': {'delimiter': 'comma', 'requireLast': false},
174 'multiline': {'delimiter': 'comma', 'requireLast': true}
175 }
176 }
177 }
178 ],
Nikolay Vitkovc62f5c52024-01-17 13:23:34179 '@typescript-eslint/no-floating-promises': ['error', {ignoreVoid: true}],
Songtao Xia165a1192021-01-28 14:09:40180 // func-call-spacing doesn't work well with .ts
Nikolay Vitkovc62f5c52024-01-17 13:23:34181 'func-call-spacing': 'off',
182 '@typescript-eslint/func-call-spacing': 'error',
Tim van der Lippe0ebbf492020-12-03 12:13:21183
Jack Franklinaba88002020-11-26 16:23:05184 /**
185 * Enforce that enum members are explicitly defined:
186 * const enum Foo { A = 'a' } rather than const enum Foo { A }
187 */
Nikolay Vitkovc62f5c52024-01-17 13:23:34188 '@typescript-eslint/prefer-enum-initializers': 'error',
Jack Franklinfc495902020-12-01 17:24:37189 /**
190 * Ban non-null assertion operator, e.g.:
191 * this.foo!.toLowerCase()
192 */
Nikolay Vitkovc62f5c52024-01-17 13:23:34193 '@typescript-eslint/no-non-null-assertion': 'error',
194 '@typescript-eslint/consistent-type-imports': 'error',
Nikolay Vitkovc62f5c52024-01-17 13:23:34195 'rulesdir/no_underscored_properties': 'error',
196 'rulesdir/prefer_readonly_keyword': 'error',
197 'rulesdir/inline_type_imports': 'error',
Tim van der Lippe399a9562020-01-16 10:53:28198 }
199 }]
Blink Reformat4c46d092018-04-07 15:32:37200};
Jack Franklindf0e9312022-12-05 10:29:52201
202// clang-format on