blob: d13be0773148a644699296aa5b8535411cd1df42 [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
78 'selector': 'TSAsExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]',
79 'message': 'Don\'t use \'querySelectorAll(...) as Type\'. Use the type parameter, \'querySelectorAll<Type>(...)\' instead',
dpapade5ef86752024-01-31 00:15:1980 },
81 {
82 // Prevent a common misuse of "!" operator.
83 "selector": "TSNonNullExpression > CallExpression > MemberExpression[property.name=/^querySelectorAll$/]",
84 "message": "Remove unnecessary \"!\" non-null operator after querySelectorAll(). It always returns a non-null result",
dpapada21b3e42024-03-18 23:51:3485 },
86 {
87 // https://google.github.io/styleguide/jsguide.html#es-module-imports
88 // 1) Matching only import URLs that have at least one '/' slash, to
89 // avoid false positives for NodeJS imports like
90 // `import fs from 'fs';`.
91 // Using '\u002F' instead of '/' as the suggested workaround for
92 // https://github.com/eslint/eslint/issues/16555
93 // 2) Allowing extensions that have a length between 2-4 characters
94 // (for example js, css, json)
95 "selector": "ImportDeclaration[source.value=/^.*\\u002F.*(?<!\\.[a-z]{2}|\\.[a-z]{3}|\\.[a-z]{4})$/]",
96 "message": "Disallowed extensionless import. Explicitly specify the extension suffix."
dpapadb9eb38f12023-11-06 21:42:0697 }],
dpapadbea253c32022-04-01 08:52:5798 'no-throw-literal': 'error',
dpapad2d023f92022-03-29 21:11:2399 'no-trailing-spaces': 'error',
Demetrios Papadopouloscf870bde2019-11-26 19:14:34100 'no-var': 'error',
101 'prefer-const': 'error',
dpapadab656922022-04-01 00:01:11102 'quotes': ['error', 'single', {allowTemplateLiterals: true}],
dpapad1e511b12017-05-31 03:31:26103 'semi': ['error', 'always'],
dpapad2674f9282017-05-31 19:40:39104
dpapadd631d172022-07-20 17:29:01105 // https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration
106 'one-var': ['error', {
107 let: 'never',
108 const: 'never',
109 }],
110
dpapadff82d512017-05-25 18:40:15111 // TODO(dpapad): Add more checks according to our styleguide.
112 },
dpapadac97d7b62021-06-14 07:20:26113
114 'overrides': [{
115 'files': ['**/*.ts'],
dpapad1c17e502023-10-04 20:31:12116 'parser': './third_party/node/node_modules/@typescript-eslint/parser/dist/index.js',
dpapadfa76653e2022-02-24 09:08:40117 'plugins': [
118 '@typescript-eslint',
119 ],
120 'rules': {
121 'no-unused-vars': 'off',
122 '@typescript-eslint/no-unused-vars': [
123 'error', {
124 argsIgnorePattern: '^_',
125 varsIgnorePattern: '^_',
126 }
dpapad5df23042022-03-21 19:22:37127 ],
128
dpapad39be89f62023-10-10 20:35:05129 // https://google.github.io/styleguide/tsguide.html#array-constructor
130 // Note: The rule below only partially enforces the styleguide, since it
131 // it does not flag invocations of the constructor with a single
132 // parameter.
133 'no-array-constructor': 'off',
134 '@typescript-eslint/no-array-constructor': 'error',
135
136 // https://google.github.io/styleguide/tsguide.html#automatic-semicolon-insertion
dpapad5df23042022-03-21 19:22:37137 'semi': 'off',
138 '@typescript-eslint/semi': ['error'],
dpapada2eca912022-03-28 09:36:44139
dpapad09279162022-07-07 18:34:06140 // https://google.github.io/styleguide/tsguide.html#arrayt-type
141 '@typescript-eslint/array-type': ['error', {
142 default: 'array-simple',
143 }],
144
dpapadd5332792022-07-11 21:15:14145 // https://google.github.io/styleguide/tsguide.html#type-assertions-syntax
146 '@typescript-eslint/consistent-type-assertions': ['error', {
147 assertionStyle: 'as',
148 }],
149
dpapadb1a935f2022-07-27 16:49:06150 // https://google.github.io/styleguide/tsguide.html#interfaces-vs-type-aliases
dpapaddc88a092023-10-04 00:19:04151 '@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
152
rbpotter38a7f0c2024-02-12 19:01:40153 // https://google.github.io/styleguide/tsguide.html#import-type
154 '@typescript-eslint/consistent-type-imports': 'error',
155
dpapaddc88a092023-10-04 00:19:04156 // https://google.github.io/styleguide/tsguide.html#visibility
157 '@typescript-eslint/explicit-member-accessibility': ['error', {
158 accessibility: 'no-public',
159 overrides: {
160 parameterProperties: 'off',
161 },
162 }],
dpapadb1a935f2022-07-27 16:49:06163
dpapad684f427b2022-05-10 05:47:02164 // https://google.github.io/styleguide/jsguide.html#naming
dpapad50adcde2022-05-07 00:05:52165 '@typescript-eslint/naming-convention': [
166 'error',
167 {
dpapad684f427b2022-05-10 05:47:02168 selector: ['class', 'interface', 'typeAlias', 'enum', 'typeParameter'],
dpapad978c1dab2022-10-19 18:12:09169 format: ['StrictPascalCase'],
170 filter: {
171 regex: '^(' +
172 // Exclude TypeScript defined interfaces HTMLElementTagNameMap
173 // and HTMLElementEventMap.
174 'HTMLElementTagNameMap|HTMLElementEventMap|' +
175 // Exclude native DOM types which are always named like HTML<Foo>Element.
176 'HTML[A-Za-z]{0,}Element|' +
177 // Exclude native DOM interfaces.
178 'UIEvent|UIEventInit|DOMError|' +
179 // Exclude the deprecated WebUIListenerBehavior interface.
180 'WebUIListenerBehavior)$',
181 match: false,
182 },
dpapad50adcde2022-05-07 00:05:52183 },
184 {
dpapad50adcde2022-05-07 00:05:52185 selector: 'enumMember',
186 format: ['UPPER_CASE'],
187 },
dpapad684f427b2022-05-10 05:47:02188 {
189 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00190 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27191 modifiers: ['public'],
192 },
193 {
194 selector: 'classMethod',
dpapade9ae77d2022-12-12 17:02:00195 format: ['strictCamelCase'],
dpapadb7286e82022-06-16 01:33:27196 modifiers: ['private'],
dpapad684f427b2022-05-10 05:47:02197 trailingUnderscore: 'allow',
dpapadd5da00a92023-05-26 17:58:23198
199 // Disallow the 'Tap_' suffix, in favor of 'Click_' in event handlers.
200 // Note: Unfortunately this ESLint rule does not provide a way to
201 // customize the error message to better inform developers.
202 custom: {
203 regex: '^on[a-zA-Z0-9]+Tap$',
204 match: false,
205 },
dpapad684f427b2022-05-10 05:47:02206 },
207 {
dpapade9d1fa72022-06-09 17:42:50208 selector: 'classProperty',
209 format: ['UPPER_CASE'],
dpapad588bb912022-06-15 05:35:33210 modifiers: ['private', 'static', 'readonly'],
211 },
212 {
213 selector: 'classProperty',
214 format: ['UPPER_CASE'],
215 modifiers: ['public', 'static', 'readonly'],
dpapade9d1fa72022-06-09 17:42:50216 },
217 {
218 selector: 'classProperty',
219 format: ['camelCase'],
dpapad588bb912022-06-15 05:35:33220 modifiers: ['public'],
221 },
222 {
223 selector: 'classProperty',
224 format: ['camelCase'],
225 modifiers: ['private'],
dpapade9d1fa72022-06-09 17:42:50226 trailingUnderscore: 'allow',
227 },
228 {
dpapad684f427b2022-05-10 05:47:02229 selector: 'parameter',
230 format: ['camelCase'],
231 leadingUnderscore: 'allow',
232 },
dpapadb17f3beb2022-05-10 21:34:13233 {
234 selector: 'function',
235 format: ['camelCase'],
236 },
dpapad50adcde2022-05-07 00:05:52237 ],
238
dpapad39be89f62023-10-10 20:35:05239 // https://google.github.io/styleguide/tsguide.html#member-property-declarations
dpapada2eca912022-03-28 09:36:44240 '@typescript-eslint/member-delimiter-style': ['error', {
241 multiline: {
242 delimiter: 'comma',
243 requireLast: true,
244 },
245 singleline: {
246 delimiter: 'comma',
247 requireLast: false,
248 },
249 overrides: {
250 interface: {
251 multiline: {
252 delimiter: 'semi',
253 requireLast: true,
254 },
255 singleline: {
256 delimiter: 'semi',
257 requireLast: false,
258 },
259 },
260 },
dpapadb5aaf1a2022-07-11 18:00:41261 }],
262
263 // https://google.github.io/styleguide/tsguide.html#wrapper-types
264 '@typescript-eslint/ban-types': ['error', {
265 extendDefaults: false,
266 types: {
267 String: {
268 message: 'Use string instead',
269 fixWith: 'string',
270 },
271 Boolean: {
272 message: 'Use boolean instead',
273 fixWith: 'boolean',
274 },
275 Number: {
276 message: 'Use number instead',
277 fixWith: 'number',
278 },
279 Symbol: {
280 message: 'Use symbol instead',
281 fixWith: 'symbol',
282 },
283 BigInt: {
284 message: 'Use bigint instead',
285 fixWith: 'bigint',
286 },
287 }
288 }],
dpapadfa76653e2022-02-24 09:08:40289 }
dpapadac97d7b62021-06-14 07:20:26290 }]
dpapadff82d512017-05-25 18:40:15291};