blob: 0953b0849688c7b505e8ce1f6b3198ef92700d43 [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']}],
dpapadb1866df2024-04-16 03:59:3627 'no-debugger': 'error',
Dan Beamb1536652019-02-26 07:36:2528 'no-extra-boolean-cast': 'error',
dpapadff82d512017-05-25 18:40:1529 'no-extra-semi': 'error',
dpapad728cff0c2017-06-01 01:06:4230 'no-new-wrappers': 'error',
dpapadd6fe5df2023-04-11 16:55:1331 'no-restricted-imports': ['error', {
32 'paths': [{
33 'name': 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js',
34 'importNames': ['Polymer'],
35 'message': 'Use PolymerElement instead.',
36 },
37 {
38 'name': '//resources/polymer/v3_0/polymer/polymer_bundled.min.js',
39 'importNames': ['Polymer'],
40 'message': 'Use PolymerElement instead.',
41 }],
42 }],
Christopher Lama5f2ad02018-12-05 10:05:5843 'no-restricted-properties': [
44 'error',
45 {
dpapad7b493a42019-06-22 02:07:0946 'property': '__lookupGetter__',
47 'message': 'Use Object.getOwnPropertyDescriptor',
48 },
49 {
50 'property': '__lookupSetter__',
51 'message': 'Use Object.getOwnPropertyDescriptor',
52 },
53 {
54 'property': '__defineGetter__',
55 'message': 'Use Object.defineProperty',
56 },
57 {
58 'property': '__defineSetter__',
59 'message': 'Use Object.defineProperty',
60 },
Dan Beam1aa00a122020-01-16 00:40:4161 {
62 'object': 'cr',
63 'property': 'exportPath',
64 'message': 'Use ES modules or cr.define() instead',
65 },
dpapad2674f9282017-05-31 19:40:3966 ],
dpapadb9eb38f12023-11-06 21:42:0667 'no-restricted-syntax': ['error', {
68 'selector': 'CallExpression[callee.object.name=JSON][callee.property.name=parse] > CallExpression[callee.object.name=JSON][callee.property.name=stringify]',
69 'message': 'Don\'t use JSON.parse(JSON.stringify(...)) to clone objects. Use structuredClone() instead.',
dpapade4b476da2024-01-25 21:56:2170 },
71 {
72 // https://google.github.io/styleguide/tsguide.html#return-type-only-generics
73 'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelector$/]',
74 'message': 'Don\'t use \'querySelector(...) as Type\'. Use the type parameter, \'querySelector<Type>(...)\' instead',
75 },
76 {
77 // https://google.github.io/styleguide/tsguide.html#return-type-only-generics
dpapada5b94b8f2024-05-01 14:03:1778 'selector': 'TSAsExpression > TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelector$/]',
79 'message': 'Don\'t use \'querySelector(...)! as Type\'. Use the type parameter, \'querySelector<Type>(...)\', followed by an assertion instead',
80 },
81 {
82 // https://google.github.io/styleguide/tsguide.html#return-type-only-generics
dpapade4b476da2024-01-25 21:56:2183 'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]',
84 'message': 'Don\'t use \'querySelectorAll(...) as Type\'. Use the type parameter, \'querySelectorAll<Type>(...)\' instead',
dpapade5ef86752024-01-31 00:15:1985 },
86 {
87 // Prevent a common misuse of "!" operator.
88 "selector": "TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]",
89 "message": "Remove unnecessary \"!\" non-null operator after querySelectorAll(). It always returns a non-null result",
dpapada21b3e42024-03-18 23:51:3490 },
91 {
92 // https://google.github.io/styleguide/jsguide.html#es-module-imports
93 // 1) Matching only import URLs that have at least one '/' slash, to
94 // avoid false positives for NodeJS imports like
95 // `import fs from 'fs';`.
96 // Using '\u002F' instead of '/' as the suggested workaround for
97 // https://github.com/eslint/eslint/issues/16555
98 // 2) Allowing extensions that have a length between 2-4 characters
99 // (for example js, css, json)
100 "selector": "ImportDeclaration[source.value=/^.*\\u002F.*(?<!\\.[a-z]{2}|\\.[a-z]{3}|\\.[a-z]{4})$/]",
101 "message": "Disallowed extensionless import. Explicitly specify the extension suffix."
dpapadb9eb38f12023-11-06 21:42:06102 }],
dpapadbea253c32022-04-01 08:52:57103 'no-throw-literal': 'error',
dpapad2d023f92022-03-29 21:11:23104 'no-trailing-spaces': 'error',
Demetrios Papadopouloscf870bde2019-11-26 19:14:34105 'no-var': 'error',
106 'prefer-const': 'error',
dpapadab656922022-04-01 00:01:11107 'quotes': ['error', 'single', {allowTemplateLiterals: true}],
dpapad1e511b12017-05-31 03:31:26108 'semi': ['error', 'always'],
dpapad2674f9282017-05-31 19:40:39109
dpapadd631d172022-07-20 17:29:01110 // https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration
111 'one-var': ['error', {
112 let: 'never',
113 const: 'never',
114 }],
115
dpapadff82d512017-05-25 18:40:15116 // TODO(dpapad): Add more checks according to our styleguide.
117 },
dpapadac97d7b62021-06-14 07:20:26118
119 'overrides': [{
120 'files': ['**/*.ts'],
dpapad1c17e502023-10-04 20:31:12121 'parser': './third_party/node/node_modules/@typescript-eslint/parser/dist/index.js',
dpapadfa76653e2022-02-24 09:08:40122 'plugins': [
123 '@typescript-eslint',
124 ],
125 'rules': {
126 'no-unused-vars': 'off',
127 '@typescript-eslint/no-unused-vars': [
128 'error', {
129 argsIgnorePattern: '^_',
130 varsIgnorePattern: '^_',
131 }
dpapad5df23042022-03-21 19:22:37132 ],
133
dpapad39be89f62023-10-10 20:35:05134 // https://google.github.io/styleguide/tsguide.html#array-constructor
135 // Note: The rule below only partially enforces the styleguide, since it
136 // it does not flag invocations of the constructor with a single
137 // parameter.
138 'no-array-constructor': 'off',
139 '@typescript-eslint/no-array-constructor': 'error',
140
141 // https://google.github.io/styleguide/tsguide.html#automatic-semicolon-insertion
dpapad5df23042022-03-21 19:22:37142 'semi': 'off',
143 '@typescript-eslint/semi': ['error'],
dpapada2eca912022-03-28 09:36:44144
dpapad09279162022-07-07 18:34:06145 // https://google.github.io/styleguide/tsguide.html#arrayt-type
146 '@typescript-eslint/array-type': ['error', {
147 default: 'array-simple',
148 }],
149
dpapadd5332792022-07-11 21:15:14150 // https://google.github.io/styleguide/tsguide.html#type-assertions-syntax
151 '@typescript-eslint/consistent-type-assertions': ['error', {
152 assertionStyle: 'as',
153 }],
154
dpapadb1a935f2022-07-27 16:49:06155 // https://google.github.io/styleguide/tsguide.html#interfaces-vs-type-aliases
dpapaddc88a092023-10-04 00:19:04156 '@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
157
rbpotter38a7f0c2024-02-12 19:01:40158 // https://google.github.io/styleguide/tsguide.html#import-type
159 '@typescript-eslint/consistent-type-imports': 'error',
160
dpapaddc88a092023-10-04 00:19:04161 // https://google.github.io/styleguide/tsguide.html#visibility
162 '@typescript-eslint/explicit-member-accessibility': ['error', {
163 accessibility: 'no-public',
164 overrides: {
165 parameterProperties: 'off',
166 },
167 }],
dpapadb1a935f2022-07-27 16:49:06168
dpapad684f427b2022-05-10 05:47:02169 // https://google.github.io/styleguide/jsguide.html#naming
dpapad50adcde2022-05-07 00:05:52170 '@typescript-eslint/naming-convention': [
171 'error',
172 {
dpapad684f427b2022-05-10 05:47:02173 selector: ['class', 'interface', 'typeAlias', 'enum', 'typeParameter'],
dpapad978c1dab2022-10-19 18:12:09174 format: ['StrictPascalCase'],
175 filter: {
176 regex: '^(' +
177 // Exclude TypeScript defined interfaces HTMLElementTagNameMap
178 // and HTMLElementEventMap.
179 'HTMLElementTagNameMap|HTMLElementEventMap|' +
180 // Exclude native DOM types which are always named like HTML<Foo>Element.
181 'HTML[A-Za-z]{0,}Element|' +
182 // Exclude native DOM interfaces.
183 'UIEvent|UIEventInit|DOMError|' +
184 // Exclude the deprecated WebUIListenerBehavior interface.
185 'WebUIListenerBehavior)$',
186 match: false,
187 },
dpapad50adcde2022-05-07 00:05:52188 },
189 {
dpapad50adcde2022-05-07 00:05:52190 selector: 'enumMember',
191 format: ['UPPER_CASE'],
192 },
dpapad684f427b2022-05-10 05:47:02193 {
194 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00195 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27196 modifiers: ['public'],
197 },
198 {
199 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00200 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27201 modifiers: ['private'],
dpapad684f427b2022-05-10 05:47:02202 trailingUnderscore: 'allow',
dpapadd5da00a92023-05-26 17:58:23203
204 // Disallow the 'Tap_' suffix, in favor of 'Click_' in event handlers.
205 // Note: Unfortunately this ESLint rule does not provide a way to
206 // customize the error message to better inform developers.
207 custom: {
208 regex: '^on[a-zA-Z0-9]+Tap$',
209 match: false,
210 },
dpapad684f427b2022-05-10 05:47:02211 },
212 {
dpapade9d1fa72022-06-09 17:42:50213 selector: 'classProperty',
214 format: ['UPPER_CASE'],
dpapad588bb912022-06-15 05:35:33215 modifiers: ['private', 'static', 'readonly'],
216 },
217 {
218 selector: 'classProperty',
219 format: ['UPPER_CASE'],
220 modifiers: ['public', 'static', 'readonly'],
dpapade9d1fa72022-06-09 17:42:50221 },
222 {
223 selector: 'classProperty',
224 format: ['camelCase'],
dpapad588bb912022-06-15 05:35:33225 modifiers: ['public'],
226 },
227 {
228 selector: 'classProperty',
229 format: ['camelCase'],
230 modifiers: ['private'],
dpapade9d1fa72022-06-09 17:42:50231 trailingUnderscore: 'allow',
232 },
233 {
dpapad684f427b2022-05-10 05:47:02234 selector: 'parameter',
235 format: ['camelCase'],
236 leadingUnderscore: 'allow',
237 },
dpapadb17f3beb2022-05-10 21:34:13238 {
239 selector: 'function',
240 format: ['camelCase'],
241 },
dpapad50adcde2022-05-07 00:05:52242 ],
243
dpapad39be89f62023-10-10 20:35:05244 // https://google.github.io/styleguide/tsguide.html#member-property-declarations
dpapada2eca912022-03-28 09:36:44245 '@typescript-eslint/member-delimiter-style': ['error', {
246 multiline: {
247 delimiter: 'comma',
248 requireLast: true,
249 },
250 singleline: {
251 delimiter: 'comma',
252 requireLast: false,
253 },
254 overrides: {
255 interface: {
256 multiline: {
257 delimiter: 'semi',
258 requireLast: true,
259 },
260 singleline: {
261 delimiter: 'semi',
262 requireLast: false,
263 },
264 },
265 },
dpapadb5aaf1a2022-07-11 18:00:41266 }],
267
268 // https://google.github.io/styleguide/tsguide.html#wrapper-types
269 '@typescript-eslint/ban-types': ['error', {
270 extendDefaults: false,
271 types: {
272 String: {
273 message: 'Use string instead',
274 fixWith: 'string',
275 },
276 Boolean: {
277 message: 'Use boolean instead',
278 fixWith: 'boolean',
279 },
280 Number: {
281 message: 'Use number instead',
282 fixWith: 'number',
283 },
284 Symbol: {
285 message: 'Use symbol instead',
286 fixWith: 'symbol',
287 },
288 BigInt: {
289 message: 'Use bigint instead',
290 fixWith: 'bigint',
291 },
292 }
293 }],
dpapade9886e42024-06-13 18:02:25294
295 // https://google.github.io/styleguide/tsguide.html#ts-ignore
296 '@typescript-eslint/ban-ts-comment': ['error', {'ts-ignore': true}],
dpapadfa76653e2022-02-24 09:08:40297 }
dpapadac97d7b62021-06-14 07:20:26298 }]
dpapadff82d512017-05-25 18:40:15299};