-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
513 lines (489 loc) · 20.1 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/**
* This file resembles what we use for our internal configuration. Several changes
* have been made to acoomodate the differences between our internal setup and
* what we would expect to see in open source.
*
* Internally we also lint each file individually, allowing use to use the file
* path to selectively enable/disable pieces of the lint configuration. For
* example, we don't actually want jest globals to be enabled all the time so
* we only enable that when we know we're linting a test file. That isn't possible
* here so we just always enable that.
*
* We are also missing our growing library of custom rules. Many of those will
* make their way out here soon, but it does mean we need to do some editing of
* our configuration object.
*/
'use strict';
// see http://eslint.org/docs/user-guide/configuring.html#configuring-rules
const OFF = 0;
const WARNING = 1;
const ERROR = 2;
// This pattern will match these texts:
// var Foo = require('Foo');
// var Bar = require('Foo').Bar;
// var BarFoo = require(Bar + 'Foo');
// var {Bar, Foo} = require('Foo');
// import type {Bar, Foo} from 'Foo';
// Also supports 'let' and 'const'.
const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
const maxLenIgnorePattern =
String.raw`^(?:var|let|const|import type)\s+` +
'{?' +
variableNamePattern +
'(?:,' +
variableNamePattern +
')*}?' +
String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./"'\s\d\-]+\)?[^;\n]*[;\n]`;
function getBaseConfig() {
return {
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
plugins: ['flowtype', 'react'],
// Tries to match the jshint configuration as closely as possible, with the
// exeception of a few things that jshint doesn't check, but that we really
// shouldn't be using anyways.
//
// Things that jshint checked for are errors, new rules are warnings.
//
// If you update eslint, be sure to check the changelog to figure out what
// rules to add/remove to/from this list.
rules: {
// Possible Errors <http://eslint.org/docs/rules/#possible-errors>
// Forked and moved to fb-www/comma-dangle
'comma-dangle': OFF,
// equivalent to jshint boss
'no-cond-assign': OFF,
// equivalent to jshint devel
'no-console': OFF,
// prohibits things like `while (true)`
'no-constant-condition': OFF,
// we need to be able to match these
'no-control-regex': OFF,
// equivalent to jshint debug
'no-debugger': ERROR,
// equivalent to jshint W004
'no-dupe-args': ERROR,
// syntax error in strict mode, almost certainly unintended in any case
'no-dupe-keys': ERROR,
// almost certainly a bug
'no-duplicate-case': WARNING,
// almost certainly a bug
'no-empty-character-class': WARNING,
// would warn on uncommented empty `catch (ex) {}` blocks
'no-empty': OFF,
// can cause subtle bugs in IE 8, and we shouldn't do this anyways
'no-ex-assign': WARNING,
// we shouldn't do this anyways
'no-extra-boolean-cast': WARNING,
// parens may be used to improve clarity, equivalent to jshint W068
'no-extra-parens': [WARNING, 'functions'],
// equivalent to jshint W032
'no-extra-semi': WARNING,
// a function delaration shouldn't be rewritable
'no-func-assign': ERROR,
// babel and es6 allow block-scoped functions
'no-inner-declarations': OFF,
// will cause a runtime error
'no-invalid-regexp': WARNING,
// disallow non-space or tab whitespace characters
'no-irregular-whitespace': WARNING,
// write `if (!(a in b))`, not `if (!a in b)`, equivalent to jshint W007
'no-negated-in-lhs': ERROR,
// will cause a runtime error
'no-obj-calls': ERROR,
// improves legibility
'no-regex-spaces': WARNING,
// equivalent to jshint elision
'no-sparse-arrays': ERROR,
// equivalent to jshint W027
'no-unreachable': ERROR,
// equivalent to jshint use-isnan
'use-isnan': ERROR,
// probably too noisy ATM
'valid-jsdoc': OFF,
// equivalent to jshint notypeof
'valid-typeof': ERROR,
// we already require semicolons
'no-unexpected-multiline': OFF,
// Best Practices <http://eslint.org/docs/rules/#best-practices>
// probably a bug, we shouldn't actually even use this yet, because of IE8
'accessor-pairs': [WARNING, { setWithoutGet: true }],
// probably too noisy ATM
'block-scoped-var': OFF,
// cyclomatic complexity, we're too far gone
complexity: OFF,
// require return statements to either always or never specify values
'consistent-return': WARNING,
// style guide: Always use brackets, even when optional.
curly: [WARNING, 'all'],
// we don't do this/care about this
'default-case': OFF,
// disabled in favor of our temporary fork
'dot-notation': OFF,
// we don't do this/care about this, but probably should eventually
'dot-location': OFF,
// disabled as it's too noisy ATM
eqeqeq: [OFF, 'allow-null'],
// we don't do this/care about this, equivalent to jshint forin
'guard-for-in': OFF,
// we have too many internal examples/tools using this
'no-alert': OFF,
// incompatible with 'use strict' equivalent to jshint noarg
'no-caller': ERROR,
// we don't care about this right now, but might later
'no-case-declarations': OFF,
// we don't do this/care about this
'no-div-regex': OFF,
// we don't do this/care about this
'no-else-return': OFF,
// avoid mistaken variables when destructuring
'no-empty-pattern': WARNING,
// see eqeqeq: we explicitly allow this, equivalent to jshint eqnull
'no-eq-null': OFF,
// equivalent to jshint evil
'no-eval': ERROR,
// should only be triggered on polyfills, which we can fix case-by-case
'no-extend-native': WARNING,
// might be a sign of a bug
'no-extra-bind': WARNING,
// equivalent to jshint W089
'no-fallthrough': WARNING,
// equivalent to jshint W008
'no-floating-decimal': ERROR,
// implicit coercion is often idiomatic
'no-implicit-coercion': OFF,
// equivalent to jshint evil/W066
'no-implied-eval': ERROR,
// will likely create more signal than noise
'no-invalid-this': OFF,
// babel should handle this fine
'no-iterator': OFF,
// Should be effectively equivalent to jshint W028 - allowing the use
// of labels in very specific situations. ESLint no-empty-labels was
// deprecated.
'no-labels': [ERROR, { allowLoop: true, allowSwitch: true }],
// lone blocks create no scope, will ignore blocks with let/const
'no-lone-blocks': WARNING,
// equivalent to jshint loopfunc
'no-loop-func': OFF,
// we surely have these, don't bother with it
'no-magic-numbers': OFF,
// we may use this for alignment in some places
'no-multi-spaces': OFF,
// equivalent to jshint multistr, consider using es6 template strings
'no-multi-str': ERROR,
// equivalent to jshint W02OFF, similar to no-extend-native
'no-native-reassign': [ERROR, { exceptions: ['Map', 'Set'] }],
// equivalent to jshint evil/W054
'no-new-func': ERROR,
// don't use constructors for side-effects, equivalent to jshint nonew
'no-new': WARNING,
// very limited uses, mostly in third_party
'no-new-wrappers': WARNING,
// deprecated in ES5, but we still use it in some places
'no-octal-escape': WARNING,
// deprecated in ES5, may cause unexpected behavior
'no-octal': WARNING,
// treats function parameters as constants, probably too noisy ATM
'no-param-reassign': OFF,
// only relevant to node code
'no-process-env': OFF,
// deprecated in ES3.WARNING, equivalent to jshint proto
'no-proto': ERROR,
// jshint doesn't catch this, but this is inexcusable
'no-redeclare': WARNING,
// equivalent to jshint boss
'no-return-assign': OFF,
// equivalent to jshint scripturl
'no-script-url': ERROR,
// not in jshint, but is in jslint, and is almost certainly a mistake
'no-self-compare': WARNING,
// there are very limited valid use-cases for this
'no-sequences': WARNING,
// we're already pretty good about this, and it hides stack traces
'no-throw-literal': WARNING,
// breaks on `foo && foo.bar()` expression statements, which are common
'no-unused-expressions': OFF,
// disallow unnecessary .call() and .apply()
'no-useless-call': WARNING,
// disallow concatenating string literals
'no-useless-concat': WARNING,
// this has valid use-cases, eg. to circumvent no-unused-expressions
'no-void': OFF,
// this journey is 1% finished (allow TODO comments)
'no-warning-comments': OFF,
// equivalent to jshint withstmt
'no-with': OFF,
// require radix argument in parseInt, we do this in most places already
radix: WARNING,
// we don't do this/care about this
'vars-on-top': OFF,
// equivalent to jshint immed
'wrap-iife': OFF,
// probably too noisy ATM
yoda: OFF,
// Strict Mode <http://eslint.org/docs/rules/#strict-mode>
// jshint wasn't checking this, and the compiler should add this anyways
strict: OFF,
// Variables <http://eslint.org/docs/rules/#variables>
// we don't do this/care about this
'init-declarations': OFF,
// equivalent to jshint W002, catches an IE8 bug
'no-catch-shadow': ERROR,
// equivalent to jshint W051, is a strict mode violation
'no-delete-var': ERROR,
// we should avoid labels anyways
'no-label-var': WARNING,
// redefining undefined, NaN, Infinity, arguments, and eval is bad, mkay?
'no-shadow-restricted-names': WARNING,
// a definite code-smell, but probably too noisy
'no-shadow': OFF,
// it's nice to be explicit sometimes: `let foo = undefined;`
'no-undef-init': OFF,
// equivalent to jshint undef, turned into an error in getConfig
'no-undef': WARNING,
// using undefined is safe because we enforce no-shadow-restricted-names
'no-undefined': OFF,
// equivalent to jshint unused
'no-unused-vars': [WARNING, { args: 'none' }],
// too noisy
'no-use-before-define': OFF,
// Node.js <http://eslint.org/docs/rules/#nodejs>
// TODO: turn some of these on in places where we lint node code
'callback-return': OFF,
'global-require': OFF,
'handle-callback-err': OFF,
'no-mixed-requires': OFF,
'no-new-require': OFF,
'no-path-concat': OFF,
'no-process-exit': OFF,
'no-restricted-modules': OFF,
'no-sync': OFF,
// Stylistic Issues <http://eslint.org/docs/rules/#stylistic-issues>
// See also: https://our.intern.facebook.com/intern/dex/style-guide/
'array-bracket-spacing': WARNING,
// TODO: enable this with consensus on single line blocks
'block-spacing': OFF,
'brace-style': [WARNING, '1tbs', { allowSingleLine: true }],
// too noisy at the moment, and jshint didn't check it
camelcase: [OFF, { properties: 'always' }],
'comma-spacing': [WARNING, { before: false, after: true }],
// jshint had laxcomma, but that was against our style guide
'comma-style': [WARNING, 'last'],
'computed-property-spacing': [WARNING, 'never'],
// we may use more contextually relevant names for this than self
'consistent-this': [OFF, 'self'],
// should be handled by a generic TXT linter instead
'eol-last': OFF,
'func-names': OFF,
// too noisy ATM
'func-style': [OFF, 'declaration'],
// no way we could enforce min/max lengths or patterns for vars
'id-length': OFF,
'id-match': OFF,
// we weren't enforcing this with jshint, so erroring would be too noisy
indent: [WARNING, 2, { SwitchCase: 1 }],
// we use single quotes for JS literals, double quotes for JSX literals
'jsx-quotes': [WARNING, 'prefer-double'],
// we may use extra spaces for alignment
'key-spacing': [OFF, { beforeColon: false, afterColon: true }],
'keyword-spacing': [WARNING],
'lines-around-comment': OFF,
// should be handled by a generic TXT linter instead
'linebreak-style': [OFF, 'unix'],
'max-depth': OFF,
'max-len': [WARNING, 120, 2, { ignorePattern: maxLenIgnorePattern }],
'max-nested-callbacks': OFF,
'max-params': OFF,
'max-statements': OFF,
// https://facebook.com/groups/995898333776940/1027358627297577
'new-cap': OFF,
// equivalent to jshint W058
'new-parens': ERROR,
'newline-after-var': OFF,
'no-array-constructor': ERROR,
'no-bitwise': WARNING,
'no-continue': OFF,
'no-inline-comments': OFF,
// doesn't play well with `if (__DEV__) {}`
'no-lonely-if': OFF,
// stopgap, irrelevant if we can eventually turn `indent` on to error
'no-mixed-spaces-and-tabs': ERROR,
// don't care
'no-multiple-empty-lines': OFF,
'no-negated-condition': OFF,
// we do this a bunch of places, and it's less bad with proper indentation
'no-nested-ternary': OFF,
// similar to FacebookWebJSLintLinter's checkPhpStyleArray
'no-new-object': WARNING,
'no-plusplus': OFF,
'no-restricted-syntax': OFF,
'no-spaced-func': WARNING,
'no-ternary': OFF,
// should be handled by a generic TXT linter instead
'no-trailing-spaces': OFF,
// we use this for private/protected identifiers
'no-underscore-dangle': OFF,
// disallow `let isYes = answer === 1 ? true : false;`
'no-unneeded-ternary': WARNING,
// too noisy ATM
'object-curly-spacing': OFF,
// makes indentation warnings clearer
'one-var': [WARNING, { initialized: 'never' }],
// prefer `x += 4` over `x = x + 4`
'operator-assignment': [WARNING, 'always'],
// equivalent to jshint laxbreak
'operator-linebreak': OFF,
'padded-blocks': OFF,
// probably too noisy on pre-ES5 code
'quote-props': [OFF, 'as-needed'],
quotes: [WARNING, 'single', 'avoid-escape'],
'require-jsdoc': OFF,
'semi-spacing': [WARNING, { before: false, after: true }],
// equivalent to jshint asi/W032
semi: [WARNING, 'always'],
'sort-vars': OFF,
// require `if () {` instead of `if (){`
'space-before-blocks': [WARNING, 'always'],
// require `function foo()` instead of `function foo ()`
'space-before-function-paren': [WARNING, { anonymous: 'never', named: 'never' }],
// incompatible with our legacy inline type annotations
'space-in-parens': [OFF, 'never'],
'space-infix-ops': [WARNING, { int32Hint: true }],
'space-unary-ops': [WARNING, { words: true, nonwords: false }],
// TODO: Figure out a way to do this that doesn't break typechecks
// or wait for https://github.com/eslint/eslint/issues/2897
'spaced-comment': [OFF, 'always', { exceptions: ['jshint', 'jslint', 'eslint', 'global'] }],
'wrap-regex': OFF,
// ECMAScript 6 <http://eslint.org/docs/rules/#ecmascript-6>
'arrow-body-style': OFF,
// Forked to fb-www/arrow-parens to fix issues with flow and add fixer
'arrow-parens': OFF,
// tbgs finds *very few* places where we don't put spaces around =>
'arrow-spacing': [WARNING, { before: true, after: true }],
// violation of the ES6 spec, won't transform
'constructor-super': ERROR,
// https://github.com/babel/babel-eslint#known-issues
'generator-star-spacing': OFF,
'no-class-assign': WARNING,
'no-confusing-arrow': OFF,
// this is a runtime error
'no-const-assign': ERROR,
'no-dupe-class-members': ERROR,
// violation of the ES6 spec, won't transform, `this` is part of the TDZ
'no-this-before-super': ERROR,
// we have way too much ES3 & ES5 code
'no-var': OFF,
'object-shorthand': OFF,
'prefer-const': OFF,
'prefer-spread': OFF,
// we don't support/polyfill this yet
'prefer-reflect': OFF,
'prefer-template': OFF,
// there are legitimate use-cases for an empty generator
'require-yield': OFF,
'no-await-in-loop': OFF,
// eslint-plugin-react <https://github.com/yannickcr/eslint-plugin-react>
// TODO: We're being extremely conservative here as we roll out eslint on
// www. As we finish rollout, we can turn on more of these, and replace
// some legacy regex rules in the process.
'react/display-name': OFF,
'react/forbid-prop-types': OFF,
'react/jsx-boolean-value': OFF,
'react/jsx-closing-bracket-location': OFF,
'react/jsx-curly-spacing': OFF,
'react/jsx-equals-spacing': WARNING,
'react/jsx-filename-extension': OFF,
'react/jsx-first-prop-new-line': OFF,
'react/jsx-handler-names': OFF,
'react/jsx-indent': OFF,
'react/jsx-indent-props': OFF,
'react/jsx-key': OFF,
'react/jsx-max-props-per-line': OFF,
'react/jsx-no-bind': OFF,
'react/jsx-no-duplicate-props': ERROR,
'react/jsx-no-literals': OFF,
'react/jsx-no-target-blank': OFF,
'react/jsx-no-undef': ERROR,
'react/jsx-pascal-case': OFF,
'react/jsx-sort-props': OFF,
'react/jsx-space-before-closing': OFF,
// forked to fb-www/jsx-uses-react
'react/jsx-uses-react': OFF,
'react/jsx-uses-vars': ERROR,
'react/no-comment-textnodes': OFF,
'react/no-danger': OFF,
'react/no-deprecated': OFF,
'react/no-did-mount-set-state': OFF,
'react/no-did-update-set-state': OFF,
'react/no-direct-mutation-state': OFF,
'react/no-is-mounted': WARNING,
'react/no-multi-comp': OFF,
'react/no-render-return-value': OFF,
'react/no-set-state': OFF,
'react/no-string-refs': OFF,
'react/no-unknown-property': OFF,
'react/prefer-es6-class': OFF,
'react/prefer-stateless-function': OFF,
'react/prop-types': OFF,
// forked to fb-www/react-in-jsx-scope
'react/react-in-jsx-scope': OFF,
'react/require-extension': OFF,
'react/require-optimization': OFF,
'react/require-render-return': OFF,
'react/self-closing-comp': OFF,
'react/sort-comp': OFF,
'react/sort-prop-types': OFF,
'react/wrap-multilines': OFF,
// eslint-plugin-flowtype
// These don't actually result in warnings. Enabling them ensures they run
// and mark variables as used, avoiding false positives with Flow
// annotations.
'flowtype/define-flow-type': WARNING,
'flowtype/use-flow-type': WARNING,
'flowtype/object-type-delimiter': [WARNING, 'comma'],
},
// Defines a basic set of globals
env: {
browser: true,
es6: true,
node: true
},
// The jshint code had more globals, which may have had something to do with
// machine-generated code. I couldn't find references with tbgs.
//
// Values of true mean the global may be modified. Values of false represent
// constants.
globals: {
__DEV__: true
},
};
}
// Override some rules for open source. Due to the way we apply our configuation
// internally, these are effectively part of the same configuration we apply.
var config = getBaseConfig();
var extendedConfig = {
rules: {
// just turned into an error here since we almost always do that anyway.
'no-undef': ERROR,
// Re-enable some forked rules. Good enough for open source
'comma-dangle': [WARNING, 'always-multiline'],
'react/jsx-uses-react': ERROR,
'react/react-in-jsx-scope': ERROR,
},
};
Object.keys(extendedConfig).forEach(key => {
config[key] = Object.assign(config[key], extendedConfig[key]);
});
module.exports = config;