blob: 78007a5d93764eb5e64137d050de812193aebcc0 [file] [log] [blame]
Avi Drissman24976592022-09-12 15:24:311// Copyright 2017 The Chromium Authors
dpapadff82d512017-05-25 18:40:152// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5module.exports = {
6 'root': true,
7 'env': {
8 'browser': true,
dpapada06173092020-10-17 03:06:169 'es2020': true,
Christopher Lama5f2ad02018-12-05 10:05:5810 },
11 'parserOptions': {
dpapada06173092020-10-17 03:06:1612 'ecmaVersion': 2020,
dpapad12b3c472019-05-29 02:16:0513 'sourceType': 'module',
dpapadff82d512017-05-25 18:40:1514 },
15 'rules': {
16 // Enabled checks.
Dan Beam1a0d9dcb2019-01-08 09:05:3517 'brace-style': ['error', '1tbs'],
dpapadf4d855722022-07-19 01:28:1818
19 // https://google.github.io/styleguide/jsguide.html#features-arrays-trailing-comma
20 // https://google.github.io/styleguide/jsguide.html#features-objects-use-trailing-comma
21 'comma-dangle': ['error', 'always-multiline'],
22
Dan Beam1a0d9dcb2019-01-08 09:05:3523 'curly': ['error', 'multi-line', 'consistent'],
dpapadc21c6fb2022-04-01 07:12:1324 'new-parens': 'error',
dpapadb2b0d6cb2022-06-27 19:45:1125 'no-array-constructor': 'error',
dpapadc7570be2022-03-28 08:28:2326 'no-console': ['error', {allow: ['info', 'warn', 'error', 'assert']}],
Dan Beamb1536652019-02-26 07:36:2527 'no-extra-boolean-cast': 'error',
dpapadff82d512017-05-25 18:40:1528 'no-extra-semi': 'error',
dpapad728cff0c2017-06-01 01:06:4229 'no-new-wrappers': 'error',
dpapadd6fe5df2023-04-11 16:55:1330 'no-restricted-imports': ['error', {
31 'paths': [{
32 'name': 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js',
33 'importNames': ['Polymer'],
34 'message': 'Use PolymerElement instead.',
35 },
36 {
37 'name': '//resources/polymer/v3_0/polymer/polymer_bundled.min.js',
38 'importNames': ['Polymer'],
39 'message': 'Use PolymerElement instead.',
40 }],
41 }],
Christopher Lama5f2ad02018-12-05 10:05:5842 'no-restricted-properties': [
43 'error',
44 {
dpapad7b493a42019-06-22 02:07:0945 'property': '__lookupGetter__',
46 'message': 'Use Object.getOwnPropertyDescriptor',
47 },
48 {
49 'property': '__lookupSetter__',
50 'message': 'Use Object.getOwnPropertyDescriptor',
51 },
52 {
53 'property': '__defineGetter__',
54 'message': 'Use Object.defineProperty',
55 },
56 {
57 'property': '__defineSetter__',
58 'message': 'Use Object.defineProperty',
59 },
Dan Beam1aa00a122020-01-16 00:40:4160 {
61 'object': 'cr',
62 'property': 'exportPath',
63 'message': 'Use ES modules or cr.define() instead',
64 },
dpapad2674f9282017-05-31 19:40:3965 ],
dpapadb9eb38f12023-11-06 21:42:0666 'no-restricted-syntax': ['error', {
67 'selector': 'CallExpression[callee.object.name=JSON][callee.property.name=parse] > CallExpression[callee.object.name=JSON][callee.property.name=stringify]',
68 'message': 'Don\'t use JSON.parse(JSON.stringify(...)) to clone objects. Use structuredClone() instead.',
dpapade4b476da2024-01-25 21:56:2169 },
70 {
71 // https://google.github.io/styleguide/tsguide.html#return-type-only-generics
72 'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelector$/]',
73 'message': 'Don\'t use \'querySelector(...) as Type\'. Use the type parameter, \'querySelector<Type>(...)\' instead',
74 },
75 {
76 // https://google.github.io/styleguide/tsguide.html#return-type-only-generics
77 'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]',
78 'message': 'Don\'t use \'querySelectorAll(...) as Type\'. Use the type parameter, \'querySelectorAll<Type>(...)\' instead',
dpapade5ef86752024-01-31 00:15:1979 },
80 {
81 // Prevent a common misuse of "!" operator.
82 "selector": "TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]",
83 "message": "Remove unnecessary \"!\" non-null operator after querySelectorAll(). It always returns a non-null result",
dpapada21b3e42024-03-18 23:51:3484 },
85 {
86 // https://google.github.io/styleguide/jsguide.html#es-module-imports
87 // 1) Matching only import URLs that have at least one '/' slash, to
88 // avoid false positives for NodeJS imports like
89 // `import fs from 'fs';`.
90 // Using '\u002F' instead of '/' as the suggested workaround for
91 // https://github.com/eslint/eslint/issues/16555
92 // 2) Allowing extensions that have a length between 2-4 characters
93 // (for example js, css, json)
94 "selector": "ImportDeclaration[source.value=/^.*\\u002F.*(?<!\\.[a-z]{2}|\\.[a-z]{3}|\\.[a-z]{4})$/]",
95 "message": "Disallowed extensionless import. Explicitly specify the extension suffix."
dpapadb9eb38f12023-11-06 21:42:0696 }],
dpapadbea253c32022-04-01 08:52:5797 'no-throw-literal': 'error',
dpapad2d023f92022-03-29 21:11:2398 'no-trailing-spaces': 'error',
Demetrios Papadopouloscf870bde2019-11-26 19:14:3499 'no-var': 'error',
100 'prefer-const': 'error',
dpapadab656922022-04-01 00:01:11101 'quotes': ['error', 'single', {allowTemplateLiterals: true}],
dpapad1e511b12017-05-31 03:31:26102 'semi': ['error', 'always'],
dpapad2674f9282017-05-31 19:40:39103
dpapadd631d172022-07-20 17:29:01104 // https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration
105 'one-var': ['error', {
106 let: 'never',
107 const: 'never',
108 }],
109
dpapadff82d512017-05-25 18:40:15110 // TODO(dpapad): Add more checks according to our styleguide.
111 },
dpapadac97d7b62021-06-14 07:20:26112
113 'overrides': [{
114 'files': ['**/*.ts'],
dpapad1c17e502023-10-04 20:31:12115 'parser': './third_party/node/node_modules/@typescript-eslint/parser/dist/index.js',
dpapadfa76653e2022-02-24 09:08:40116 'plugins': [
117 '@typescript-eslint',
118 ],
119 'rules': {
120 'no-unused-vars': 'off',
121 '@typescript-eslint/no-unused-vars': [
122 'error', {
123 argsIgnorePattern: '^_',
124 varsIgnorePattern: '^_',
125 }
dpapad5df23042022-03-21 19:22:37126 ],
127
dpapad39be89f62023-10-10 20:35:05128 // https://google.github.io/styleguide/tsguide.html#array-constructor
129 // Note: The rule below only partially enforces the styleguide, since it
130 // it does not flag invocations of the constructor with a single
131 // parameter.
132 'no-array-constructor': 'off',
133 '@typescript-eslint/no-array-constructor': 'error',
134
135 // https://google.github.io/styleguide/tsguide.html#automatic-semicolon-insertion
dpapad5df23042022-03-21 19:22:37136 'semi': 'off',
137 '@typescript-eslint/semi': ['error'],
dpapada2eca912022-03-28 09:36:44138
dpapad09279162022-07-07 18:34:06139 // https://google.github.io/styleguide/tsguide.html#arrayt-type
140 '@typescript-eslint/array-type': ['error', {
141 default: 'array-simple',
142 }],
143
dpapadd5332792022-07-11 21:15:14144 // https://google.github.io/styleguide/tsguide.html#type-assertions-syntax
145 '@typescript-eslint/consistent-type-assertions': ['error', {
146 assertionStyle: 'as',
147 }],
148
dpapadb1a935f2022-07-27 16:49:06149 // https://google.github.io/styleguide/tsguide.html#interfaces-vs-type-aliases
dpapaddc88a092023-10-04 00:19:04150 '@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
151
rbpotter38a7f0c2024-02-12 19:01:40152 // https://google.github.io/styleguide/tsguide.html#import-type
153 '@typescript-eslint/consistent-type-imports': 'error',
154
dpapaddc88a092023-10-04 00:19:04155 // https://google.github.io/styleguide/tsguide.html#visibility
156 '@typescript-eslint/explicit-member-accessibility': ['error', {
157 accessibility: 'no-public',
158 overrides: {
159 parameterProperties: 'off',
160 },
161 }],
dpapadb1a935f2022-07-27 16:49:06162
dpapad684f427b2022-05-10 05:47:02163 // https://google.github.io/styleguide/jsguide.html#naming
dpapad50adcde2022-05-07 00:05:52164 '@typescript-eslint/naming-convention': [
165 'error',
166 {
dpapad684f427b2022-05-10 05:47:02167 selector: ['class', 'interface', 'typeAlias', 'enum', 'typeParameter'],
dpapad978c1dab2022-10-19 18:12:09168 format: ['StrictPascalCase'],
169 filter: {
170 regex: '^(' +
171 // Exclude TypeScript defined interfaces HTMLElementTagNameMap
172 // and HTMLElementEventMap.
173 'HTMLElementTagNameMap|HTMLElementEventMap|' +
174 // Exclude native DOM types which are always named like HTML<Foo>Element.
175 'HTML[A-Za-z]{0,}Element|' +
176 // Exclude native DOM interfaces.
177 'UIEvent|UIEventInit|DOMError|' +
178 // Exclude the deprecated WebUIListenerBehavior interface.
179 'WebUIListenerBehavior)$',
180 match: false,
181 },
dpapad50adcde2022-05-07 00:05:52182 },
183 {
dpapad50adcde2022-05-07 00:05:52184 selector: 'enumMember',
185 format: ['UPPER_CASE'],
186 },
dpapad684f427b2022-05-10 05:47:02187 {
188 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00189 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27190 modifiers: ['public'],
191 },
192 {
193 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00194 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27195 modifiers: ['private'],
dpapad684f427b2022-05-10 05:47:02196 trailingUnderscore: 'allow',
dpapadd5da00a92023-05-26 17:58:23197
198 // Disallow the 'Tap_' suffix, in favor of 'Click_' in event handlers.
199 // Note: Unfortunately this ESLint rule does not provide a way to
200 // customize the error message to better inform developers.
201 custom: {
202 regex: '^on[a-zA-Z0-9]+Tap$',
203 match: false,
204 },
dpapad684f427b2022-05-10 05:47:02205 },
206 {
dpapade9d1fa72022-06-09 17:42:50207 selector: 'classProperty',
208 format: ['UPPER_CASE'],
dpapad588bb912022-06-15 05:35:33209 modifiers: ['private', 'static', 'readonly'],
210 },
211 {
212 selector: 'classProperty',
213 format: ['UPPER_CASE'],
214 modifiers: ['public', 'static', 'readonly'],
dpapade9d1fa72022-06-09 17:42:50215 },
216 {
217 selector: 'classProperty',
218 format: ['camelCase'],
dpapad588bb912022-06-15 05:35:33219 modifiers: ['public'],
220 },
221 {
222 selector: 'classProperty',
223 format: ['camelCase'],
224 modifiers: ['private'],
dpapade9d1fa72022-06-09 17:42:50225 trailingUnderscore: 'allow',
226 },
227 {
dpapad684f427b2022-05-10 05:47:02228 selector: 'parameter',
229 format: ['camelCase'],
230 leadingUnderscore: 'allow',
231 },
dpapadb17f3beb2022-05-10 21:34:13232 {
233 selector: 'function',
234 format: ['camelCase'],
235 },
dpapad50adcde2022-05-07 00:05:52236 ],
237
dpapad39be89f62023-10-10 20:35:05238 // https://google.github.io/styleguide/tsguide.html#member-property-declarations
dpapada2eca912022-03-28 09:36:44239 '@typescript-eslint/member-delimiter-style': ['error', {
240 multiline: {
241 delimiter: 'comma',
242 requireLast: true,
243 },
244 singleline: {
245 delimiter: 'comma',
246 requireLast: false,
247 },
248 overrides: {
249 interface: {
250 multiline: {
251 delimiter: 'semi',
252 requireLast: true,
253 },
254 singleline: {
255 delimiter: 'semi',
256 requireLast: false,
257 },
258 },
259 },
dpapadb5aaf1a2022-07-11 18:00:41260 }],
261
262 // https://google.github.io/styleguide/tsguide.html#wrapper-types
263 '@typescript-eslint/ban-types': ['error', {
264 extendDefaults: false,
265 types: {
266 String: {
267 message: 'Use string instead',
268 fixWith: 'string',
269 },
270 Boolean: {
271 message: 'Use boolean instead',
272 fixWith: 'boolean',
273 },
274 Number: {
275 message: 'Use number instead',
276 fixWith: 'number',
277 },
278 Symbol: {
279 message: 'Use symbol instead',
280 fixWith: 'symbol',
281 },
282 BigInt: {
283 message: 'Use bigint instead',
284 fixWith: 'bigint',
285 },
286 }
287 }],
dpapadfa76653e2022-02-24 09:08:40288 }
dpapadac97d7b62021-06-14 07:20:26289 }]
dpapadff82d512017-05-25 18:40:15290};