forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
310 lines (298 loc) · 9.79 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
// vim: foldmethod=marker:foldmarker={{{,}}}
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// ESlint config
// This is a matcher (usable in no-restricted-syntax) that matches either a
// test or a before/after block.
const testNameRegex =
'/^([fx]?it|(drm|quarantined)It|(before|after)(Each|All))$/';
const testCall = `CallExpression[callee.name=${testNameRegex}]`;
const commonNoRestrictedSyntax = [
{
'selector':
'MemberExpression[object.name="goog"][property.name="inherits"]',
'message': 'Don\'t use goog.inherits.',
},
{
'selector': ':not(MethodDefinition) > FunctionExpression',
'message': 'Use arrow functions instead of "function" functions.',
},
{
'selector': 'CallExpression[callee.property.name="forEach"] >' +
':function[params.length=1]',
'message': 'Use for-of instead of forEach',
},
{
// NOTE: prefer-spread rule covers .apply() already.
'selector': 'CallExpression[callee.property.name=/^(bind|call)$/]',
'message': 'Don\'t use Function bind/call.',
},
{
'selector': 'MemberExpression[property.name="prototype"]',
'message': 'Use ES6 classes not .prototype.',
},
{
'selector': 'BinaryExpression[operator=/^([<>!=]=?)$/] > ' +
'CallExpression[callee.property.name=indexOf]',
'message': 'Use Array.includes instead of indexOf.',
},
];
module.exports = {
'env': {
'browser': true,
'es6': true,
},
'parserOptions': {
'ecmaVersion': 2017,
},
'extends': ['eslint:recommended', 'google', 'plugin:shaka-rules/config'],
'rules': {
// Things the compiler already takes care of, with more precision: {{{
'no-console': 'off',
'no-eq-null': 'off',
'no-eval': 'off',
'no-undef': 'off',
'valid-jsdoc': 'off',
// }}}
// Things we should probably fix, but in stages in multiple commits: {{{
// These could catch real bugs
'default-case': 'off',
// TODO: Enable no-loop-func in next eslint release. We can't use it
// now since it doesn't allow capturing "const" variables, which is safe
'no-loop-func': 'off',
'no-unused-expressions': 'off', // Conflicts with some Closure declarations
'prefer-promise-reject-errors': 'off',
// These could improve readability
'complexity': 'off',
'no-negated-condition': 'off',
'no-shadow': 'off',
// }}}
// "Possible error" rules: {{{
'no-async-promise-executor': 'error',
'no-await-in-loop': 'error',
'no-empty': ['error', {'allowEmptyCatch': true}],
'no-misleading-character-class': 'error',
'no-template-curly-in-string': 'error',
'no-fallthrough': ['error', {'allowEmptyCase': true}],
// TODO: Try to re-enable this if possible. Right now, it produces way too
// many false-positives with eslint 7. It worked well enough in eslint 5.
// 'require-atomic-updates': 'error',
// }}}
// "Best practices" rules: {{{
'accessor-pairs': 'error',
'array-callback-return': 'error',
// causes issues when implementing an interface
'class-methods-use-this': 'off',
'consistent-return': 'error',
'dot-location': ['error', 'property'],
'dot-notation': 'off', // We use bracket notation in tests on purpose
'eqeqeq': 'off', // Compiler handles type checking in advance
'guard-for-in': 'off',
'no-alert': 'error',
'no-caller': 'error',
'no-div-regex': 'error',
'no-extend-native': 'error', // May conflict with future polyfills
'no-extra-label': 'error',
'no-floating-decimal': 'error',
'no-implicit-coercion': ['error', {'allow': ['!!']}],
'no-implied-eval': 'error',
'no-invalid-this': 'error',
'no-iterator': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-multi-spaces': ['error', {'ignoreEOLComments': true}],
'no-multi-str': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-octal-escape': 'error',
'no-proto': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-script-url': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-throw-literal': 'error',
'no-unmodified-loop-condition': 'error',
'no-unused-vars': 'off', // Interface impls may not require all args
'no-useless-call': 'error',
'no-useless-catch': 'error',
'no-useless-concat': 'error',
'no-useless-return': 'error',
'no-void': 'error',
'no-warning-comments': 'off', // TODO and FIXME are fine
'radix': ['error', 'always'],
'require-await': 'error',
'wrap-iife': ['error', 'inside'],
'yoda': ['error', 'never'],
// }}}
// "Variables" rules: {{{
'no-label-var': 'error',
'no-shadow-restricted-names': 'error',
'no-undef-init': 'off', // Sometimes necessary with hacky compiler casts
'no-undefined': 'off', // We use undefined in many places, legitimately
// Does not know when things are executed, false positives
'no-use-before-define': 'off',
// }}}
// "Stylistic Issues" rules: {{{
'array-bracket-newline': ['error', 'consistent'],
'block-spacing': ['error', 'always'],
'brace-style': ['error', '1tbs', {'allowSingleLine': true}],
'id-denylist': ['error', 'async'],
'lines-between-class-members': 'error',
'max-statements-per-line': ['error', {'max': 1}],
'new-parens': 'error',
'no-mixed-operators': [
'error', {
'groups': [['&', '|', '^', '~', '<<', '>>', '>>>', '&&', '||']],
'allowSamePrecedence': false,
},
],
'no-restricted-syntax': [
'error',
...commonNoRestrictedSyntax,
],
'no-whitespace-before-property': 'error',
'nonblock-statement-body-position': ['error', 'below'],
'operator-assignment': 'error',
'spaced-comment': ['error', 'always', {
// Characters which may be glued to the start of a comment block, but
// which do not violate the rule. The "*" is for jsdoc's "/**" syntax,
// and the "!" is for the "/*!" of license headers which are passed
// verbatim through the compiler.
'markers': ['*', '!'],
}],
'require-jsdoc': ['error', {
'require': {
'FunctionDeclaration': true,
'MethodDefinition': true,
'ClassDeclaration': true,
},
}],
// }}}
// "ECMAScript 6" rules: {{{
'arrow-spacing': 'error',
'no-useless-constructor': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': ['error', {'ignoreReadBeforeAssign': true}],
// }}}
},
'overrides': [
{
'rules': {
'no-restricted-syntax': [
'error',
{
'selector': 'CallExpression[callee.name="beforeAll"] ' +
':matches(' +
'CallExpression[callee.property.name="createSpy"],' +
'CallExpression[callee.name="spyOn"])',
'message': 'Create spies in beforeEach, not beforeAll.',
},
{
'selector': testCall + ' > :function[params.length>0]',
'message': 'Use async instead of "done" in tests.',
},
{
'selector': testCall + ' > CallExpression',
'message': 'Use filterDescribe instead of checkAndRun calls',
},
{
'selector': 'CatchClause',
'message': 'Use expect.toThrow or expectAsync.toBeRejected',
},
{
'selector': 'CallExpression[callee.name=expect] >' +
'CallExpression[callee.property.name=count]' +
'[callee.object.property.name=calls]',
'message': 'Use expect.toHaveBeenCalledTimes',
},
{
'selector':
'CallExpression[callee.property.name=toHaveBeenCalledTimes] >' +
'Literal[value=0]',
'message': 'Use expect.not.toHaveBeenCalled',
},
...commonNoRestrictedSyntax,
],
},
'files': [
'test/**/*.js',
],
},
{
'rules': {
'no-restricted-syntax': 'off',
},
'files': [
'demo/load.js',
'externs/**/*.js',
'test/test/externs/*.js',
'ui/externs/*.js',
],
},
{
'rules': {
'no-var': 'off',
},
'files': [
// Closure requires using var in externs.
'ui/externs/*.js',
'externs/**/*.js',
'test/test/externs/*.js',
// Use var in load.js so it works in old browsers. We'll use
// compiled mode for the main library and the demo.
'demo/load.js',
],
},
{
'rules': {
'prefer-rest-params': 'off',
},
'files': [
// Test code should still use "arguments", since the alternate
// "rest parameter" syntax won't work in uncompiled code on IE.
'test/**/*.js',
// These two files use "arguments" to patch over functions. It
// is difficult to reason about whether or not these instances
// would always work with rest parameters, so just allow them to
// use "arguments".
'demo/log_section.js',
'lib/debug/asserts.js',
],
},
{
'rules': {
// Disable rules on useless constructors so we can use ES6 classes in
// externs.
'no-useless-constructor': 'off',
},
'files': ['externs/**/*.js'],
},
{
'rules': {
// JSDoc is not strictly required in externs, tests, and in load.js.
'require-jsdoc': 'off',
},
'files': [
'demo/load.js',
'externs/**/*.js',
'test/**/*.js',
],
},
{
'rules': {
// Externs naturally redeclare things eslint knows about.
'no-redeclare': 'off',
},
'files': [
'ui/externs/*.js',
'externs/**/*.js',
'test/test/externs/*.js',
],
},
],
};