-
Notifications
You must be signed in to change notification settings - Fork 472
/
.eslintrc.js
316 lines (286 loc) · 10.5 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
const path = require('path');
const rulesDirPlugin = require('eslint-plugin-rulesdir');
rulesDirPlugin.RULES_DIR = path.join(__dirname, 'scripts', 'eslint_rules', 'lib');
module.exports = {
root: true,
env: {browser: true, es6: true},
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'mocha',
'rulesdir',
'import',
'jsdoc',
],
parserOptions: {ecmaVersion: 9, sourceType: 'module'},
/**
* ESLint rules
*
* All available rules: http://eslint.org/docs/rules/
*/
rules: {
/**
* Enforced rules
*/
// syntax preferences
quotes: ['error', 'single', {avoidEscape: true, allowTemplateLiterals: false}],
semi: 'error',
'no-extra-semi': 'error',
'comma-style': ['error', 'last'],
'wrap-iife': ['error', 'inside'],
'spaced-comment': ['error', 'always', {markers: ['*']}],
eqeqeq: 'error',
'accessor-pairs': ['error', {getWithoutSet: false, setWithoutGet: false}],
curly: 'error',
'new-parens': 'error',
'func-call-spacing': 'error',
'arrow-parens': ['error', 'as-needed'],
'eol-last': 'error',
'object-shorthand': ['error', 'properties'],
'no-useless-rename': 'error',
// anti-patterns
'no-caller': 'error',
'no-case-declarations': 'error',
'no-cond-assign': 'error',
'no-console': ['error', {allow: ['assert', 'context', 'error', 'timeStamp', 'time', 'timeEnd', 'warn']}],
'no-debugger': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-else-return': ['error', {allowElseIf: false}],
'no-empty-character-class': 'error',
'no-global-assign': 'error',
'no-implied-eval': 'error',
'no-labels': 'error',
'no-multi-str': 'error',
'no-new-object': 'error',
'no-octal-escape': 'error',
'no-self-compare': 'error',
'no-shadow-restricted-names': 'error',
'no-unreachable': 'error',
'no-unsafe-negation': 'error',
'no-unused-vars': ['error', {args: 'none', vars: 'local'}],
'no-var': 'error',
'no-with': 'error',
'prefer-const': 'error',
radix: 'error',
'valid-typeof': 'error',
'no-return-assign': ['error', 'always'],
'no-implicit-coercion': 'error',
// es2015 features
'require-yield': 'error',
'template-curly-spacing': ['error', 'never'],
// file whitespace
'no-multiple-empty-lines': ['error', {max: 1}],
'no-mixed-spaces-and-tabs': 'error',
'no-trailing-spaces': 'error',
'linebreak-style': ['error', 'unix'],
/**
* Disabled, aspirational rules
*/
indent: ['off', 2, {SwitchCase: 1, CallExpression: {arguments: 2}, MemberExpression: 2}],
// brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions
'brace-style': ['off', 'allman', {allowSingleLine: true}],
// key-spacing is disabled, as some objects use value-aligned spacing, some not.
'key-spacing': ['off', {beforeColon: false, afterColon: true, align: 'value'}],
'quote-props': ['error', 'as-needed'],
// no-implicit-globals will prevent accidental globals
'no-implicit-globals': 'off',
'no-unused-private-class-members': 'error',
// forbids interfaces starting with an I prefix.
'@typescript-eslint/naming-convention':
['error', {selector: 'interface', format: ['PascalCase'], custom: {regex: '^I[A-Z]', match: false}}],
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-explicit-any': [
'error',
{
ignoreRestArgs: true
}
],
// Closure does not properly typecheck default exports
'import/no-default-export': 'error',
/**
* Catch duplicate import paths. For example this would catch the following example:
* import {Foo} from './foo.js'
* import * as FooModule from './foo.js'
**/
'import/no-duplicates': 'error',
// Try to spot '// console.log()' left over from debugging
'rulesdir/no-commented-out-console': 'error',
// Prevent imports being commented out rather than deleted.
'rulesdir/no-commented-out-import': 'error',
// DevTools specific rules
'rulesdir/es-modules-import': 'error',
'rulesdir/check-license-header': 'error',
'rulesdir/html-tagged-template': 'error',
/**
* Ensures that JS Doc comments are properly aligned - all the starting
* `*` are in the right place.
*/
'jsdoc/check-alignment': 'error',
},
overrides: [{
files: ['*.ts'],
parserOptions: {
allowAutomaticSingleRunInference: true,
project: path.join(__dirname, 'config', 'typescript', 'tsconfig.eslint.json'),
},
rules: {
'@typescript-eslint/explicit-member-accessibility': ['error', {accessibility: 'no-public'}],
'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
// run just the TypeScript unused-vars rule, else we get duplicate errors
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', {argsIgnorePattern: '^_'}],
// run just the TypeScript semi rule, else we get duplicate errors
semi: 'off',
'@typescript-eslint/semi': 'error',
'@typescript-eslint/member-delimiter-style': [
'error', {
multiline: {delimiter: 'semi', requireLast: true},
singleline: {delimiter: 'comma', requireLast: false},
overrides: {
interface: {
singleline: {delimiter: 'semi', requireLast: false},
multiline: {delimiter: 'semi', requireLast: true}
},
typeLiteral: {
singleline: {delimiter: 'comma', requireLast: false},
multiline: {delimiter: 'comma', requireLast: true}
}
}
}
],
'@typescript-eslint/no-floating-promises': ['error', {ignoreVoid: true}],
// func-call-spacing doesn't work well with .ts
'func-call-spacing': 'off',
'@typescript-eslint/func-call-spacing': 'error',
/**
* Enforce that enum members are explicitly defined:
* const enum Foo { A = 'a' } rather than const enum Foo { A }
*/
'@typescript-eslint/prefer-enum-initializers': 'error',
/**
* Ban non-null assertion operator, e.g.:
* this.foo!.toLowerCase()
*/
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'rulesdir/no-underscored-properties': 'error',
'rulesdir/prefer-readonly-keyword': 'error',
'rulesdir/inline-type-imports': 'error',
'rulesdir/enforce-default-import-name': ['error', {
// Enforce that any import of models/trace/trace.js names the import Trace.
modulePath: path.join(__dirname, 'front_end', 'models', 'trace', 'trace.js'),
importName: 'Trace'
}]
}
}, {
files : ['*.ts'],
rules : {
'@typescript-eslint/naming-convention' :
[
'error', {
selector : ['function', 'accessor', 'method', 'property', 'parameterProperty'],
format : ['camelCase'],
},
{
selector: 'variable',
filter: {
// Ignore localization variables.
regex: '^(UIStrings|str_)$',
match: false
},
format: ['camelCase'],
},
{
// We are using camelCase, PascalCase and UPPER_CASE for top-level constants, allow the for now.
selector: 'variable',
modifiers: ['const'],
filter: {
// Ignore localization variables.
regex: '^(UIStrings|str_)$',
match: false
},
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
},
{
selector : 'classProperty',
modifiers : ['static', 'readonly'],
format : ['UPPER_CASE', 'camelCase'],
},
{
selector : 'enumMember',
format : ['UPPER_CASE'],
},
{
selector : ['typeLike'],
format : ['PascalCase'],
},
{
selector : 'parameter',
format : ['camelCase'],
leadingUnderscore : 'allow',
},
{
// Public methods are currently in transition and may still have leading underscores.
selector: 'method',
modifiers: ['public'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
{
selector: 'property',
modifiers: ['public'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
{
// Object literals may be constructed as arguments to external libraries which follow different styles.
selector: ['objectLiteralMethod', 'objectLiteralProperty'],
modifiers: ['public'],
format: null,
},
{
// Ignore type properties that require quotes
selector : 'typeProperty',
format : null,
modifiers : ['requiresQuotes']
}
]
}
}, {
files: ['*.test.ts', 'test/**/*.ts', '**/testing/*.ts'],
rules: {
// errors on it('test') with no body
'mocha/no-pending-tests' : 'error',
// errors on {describe, it}.only
'mocha/no-exclusive-tests' : 'error',
'mocha/no-async-describe': 'error',
'mocha/no-global-tests': 'error',
'mocha/no-nested-tests': 'error',
'rulesdir/check-test-definitions' : 'error',
'rulesdir/no-assert-equal' : 'error',
'rulesdir/no-assert-deep-strict-equal' : 'error',
'rulesdir/no-repeated-tests' : 'error',
'rulesdir/compare-arrays-with-assert-deepequal' : 'error',
'rulesdir/no-screenshot-test-outside-perf-panel' : 'error',
'rulesdir/trace-engine-test-timeouts' : 'error',
'@typescript-eslint/no-non-null-assertion' : 'off',
},
settings: {
'mocha/additionalCustomNames': [
{ name: 'describeWithDevtoolsExtension', type: 'suite', interfaces: [ 'BDD', 'TDD' ] },
{ name: 'describeWithEnvironment', type: 'suite', interfaces: [ 'BDD', 'TDD' ] },
{ name: 'describeWithLocale', type: 'suite', interfaces: [ 'BDD', 'TDD' ] },
{ name: 'describeWithMockConnection', type: 'suite', interfaces: [ 'BDD', 'TDD' ] },
{ name: 'describeWithRealConnection', type: 'suite', interfaces: [ 'BDD', 'TDD' ] },
{ name: 'itScreenshot', type: 'testCase', interfaces: [ 'BDD', 'TDD' ] },
]
}
}],
};
// clang-format on