1 | /**
|
2 | * Copyright 2013-2015, Facebook, Inc.
|
3 | * All rights reserved.
|
4 | *
|
5 | * This source code is licensed under the BSD-style license found in the
|
6 | * LICENSE file in the root directory of this source tree. An additional grant
|
7 | * of patent rights can be found in the PATENTS file in the same directory.
|
8 | */
|
9 |
|
10 | /**
|
11 | * This file resembles what we use for our internal configuration. Several changes
|
12 | * have been made to acoomodate the differences between our internal setup and
|
13 | * what we would expect to see in open source.
|
14 | *
|
15 | * Internally we also lint each file individually, allowing use to use the file
|
16 | * path to selectively enable/disable pieces of the lint configuration. For
|
17 | * example, we don't actually want jest globals to be enabled all the time so
|
18 | * we only enable that when we know we're linting a test file. That isn't possible
|
19 | * here so we just always enable that.
|
20 | *
|
21 | * We are also missing our growing library of custom rules. Many of those will
|
22 | * make their way out here soon, but it does mean we need to do some editing of
|
23 | * our configuration object.
|
24 | */
|
25 |
|
26 | ;
|
27 |
|
28 | // see http://eslint.org/docs/user-guide/configuring.html#configuring-rules
|
29 | const OFF = 0;
|
30 | const WARNING = 1;
|
31 | const ERROR = 2;
|
32 |
|
33 | // This pattern will match these texts:
|
34 | // var Foo = require('Foo');
|
35 | // var Bar = require('Foo').Bar;
|
36 | // var BarFoo = require(Bar + 'Foo');
|
37 | // var {Bar, Foo} = require('Foo');
|
38 | // import type {Bar, Foo} from 'Foo';
|
39 | // Also supports 'let' and 'const'.
|
40 | const variableNamePattern = String.raw`\s*[a-zA-Z_$][a-zA-Z_$\d]*\s*`;
|
41 | const maxLenIgnorePattern = String.raw`^(?:var|let|const|import type)\s+` +
|
42 | '{?' + variableNamePattern + '(?:,' + variableNamePattern + ')*}?' +
|
43 | String.raw`\s*(?:=\s*require\(|from)[a-zA-Z_+./"'\s\d\-]+\)?[^;\n]*[;\n]`;
|
44 |
|
45 | function getBaseConfig() {
|
46 | return {
|
47 | parser: 'babel-eslint',
|
48 | parserOptions: {
|
49 | ecmaVersion: 6,
|
50 | sourceType: 'module',
|
51 | },
|
52 |
|
53 | plugins: [
|
54 | 'babel',
|
55 | 'flow-vars',
|
56 | 'react',
|
57 | ],
|
58 |
|
59 | // Tries to match the jshint configuration as closely as possible, with the
|
60 | // exeception of a few things that jshint doesn't check, but that we really
|
61 | // shouldn't be using anyways.
|
62 | //
|
63 | // Things that jshint checked for are errors, new rules are warnings.
|
64 | //
|
65 | // If you update eslint, be sure to check the changelog to figure out what
|
66 | // rules to add/remove to/from this list.
|
67 | rules: {
|
68 | // Possible Errors <http://eslint.org/docs/rules/#possible-errors>
|
69 |
|
70 | // Forked and moved to fb-www/comma-dangle
|
71 | 'comma-dangle': OFF,
|
72 | // equivalent to jshint boss
|
73 | 'no-cond-assign': OFF,
|
74 | // equivalent to jshint devel
|
75 | 'no-console': OFF,
|
76 | // prohibits things like `while (true)`
|
77 | 'no-constant-condition': OFF,
|
78 | // we need to be able to match these
|
79 | 'no-control-regex': OFF,
|
80 | // equivalent to jshint debug
|
81 | 'no-debugger': ERROR,
|
82 | // equivalent to jshint W004
|
83 | 'no-dupe-args': ERROR,
|
84 | // syntax error in strict mode, almost certainly unintended in any case
|
85 | 'no-dupe-keys': ERROR,
|
86 | // almost certainly a bug
|
87 | 'no-duplicate-case': WARNING,
|
88 | // almost certainly a bug
|
89 | 'no-empty-character-class': WARNING,
|
90 | // would warn on uncommented empty `catch (ex) {}` blocks
|
91 | 'no-empty': OFF,
|
92 | // can cause subtle bugs in IE 8, and we shouldn't do this anyways
|
93 | 'no-ex-assign': WARNING,
|
94 | // we shouldn't do this anyways
|
95 | 'no-extra-boolean-cast': WARNING,
|
96 | // parens may be used to improve clarity, equivalent to jshint W068
|
97 | 'no-extra-parens': [WARNING, 'functions'],
|
98 | // equivalent to jshint W032
|
99 | 'no-extra-semi': WARNING,
|
100 | // a function delaration shouldn't be rewritable
|
101 | 'no-func-assign': ERROR,
|
102 | // babel and es6 allow block-scoped functions
|
103 | 'no-inner-declarations': OFF,
|
104 | // will cause a runtime error
|
105 | 'no-invalid-regexp': WARNING,
|
106 | // disallow non-space or tab whitespace characters
|
107 | 'no-irregular-whitespace': WARNING,
|
108 | // write `if (!(a in b))`, not `if (!a in b)`, equivalent to jshint W007
|
109 | 'no-negated-in-lhs': ERROR,
|
110 | // will cause a runtime error
|
111 | 'no-obj-calls': ERROR,
|
112 | // improves legibility
|
113 | 'no-regex-spaces': WARNING,
|
114 | // equivalent to jshint elision
|
115 | 'no-sparse-arrays': ERROR,
|
116 | // equivalent to jshint W027
|
117 | 'no-unreachable': ERROR,
|
118 | // equivalent to jshint use-isnan
|
119 | 'use-isnan': ERROR,
|
120 | // probably too noisy ATM
|
121 | 'valid-jsdoc': OFF,
|
122 | // equivalent to jshint notypeof
|
123 | 'valid-typeof': ERROR,
|
124 | // we already require semicolons
|
125 | 'no-unexpected-multiline': OFF,
|
126 |
|
127 | // Best Practices <http://eslint.org/docs/rules/#best-practices>
|
128 |
|
129 | // probably a bug, we shouldn't actually even use this yet, because of IE8
|
130 | 'accessor-pairs': [WARNING, {setWithoutGet: true}],
|
131 | // probably too noisy ATM
|
132 | 'block-scoped-var': OFF,
|
133 | // cyclomatic complexity, we're too far gone
|
134 | 'complexity': OFF,
|
135 | // require return statements to either always or never specify values
|
136 | 'consistent-return': WARNING,
|
137 | // style guide: Always use brackets, even when optional.
|
138 | 'curly': [WARNING, 'all'],
|
139 | // we don't do this/care about this
|
140 | 'default-case': OFF,
|
141 | // disabled in favor of our temporary fork
|
142 | 'dot-notation': OFF,
|
143 | // we don't do this/care about this, but probably should eventually
|
144 | 'dot-location': OFF,
|
145 | // disabled as it's too noisy ATM
|
146 | 'eqeqeq': [OFF, 'allow-null'],
|
147 | // we don't do this/care about this, equivalent to jshint forin
|
148 | 'guard-for-in': OFF,
|
149 | // we have too many internal examples/tools using this
|
150 | 'no-alert': OFF,
|
151 | // incompatible with 'use strict' equivalent to jshint noarg
|
152 | 'no-caller': ERROR,
|
153 | // we don't care about this right now, but might later
|
154 | 'no-case-declarations': OFF,
|
155 | // we don't do this/care about this
|
156 | 'no-div-regex': OFF,
|
157 | // we don't do this/care about this
|
158 | 'no-else-return': OFF,
|
159 | // avoid mistaken variables when destructuring
|
160 | 'no-empty-pattern': WARNING,
|
161 | // see eqeqeq: we explicitly allow this, equivalent to jshint eqnull
|
162 | 'no-eq-null': OFF,
|
163 | // equivalent to jshint evil
|
164 | 'no-eval': ERROR,
|
165 | // should only be triggered on polyfills, which we can fix case-by-case
|
166 | 'no-extend-native': WARNING,
|
167 | // might be a sign of a bug
|
168 | 'no-extra-bind': WARNING,
|
169 | // equivalent to jshint W089
|
170 | 'no-fallthrough': WARNING,
|
171 | // equivalent to jshint W008
|
172 | 'no-floating-decimal': ERROR,
|
173 | // implicit coercion is often idiomatic
|
174 | 'no-implicit-coercion': OFF,
|
175 | // equivalent to jshint evil/W066
|
176 | 'no-implied-eval': ERROR,
|
177 | // will likely create more signal than noise
|
178 | 'no-invalid-this': OFF,
|
179 | // babel should handle this fine
|
180 | 'no-iterator': OFF,
|
181 | // Should be effectively equivalent to jshint W028 - allowing the use
|
182 | // of labels in very specific situations. ESLint no-empty-labels was
|
183 | // deprecated.
|
184 | 'no-labels': [ERROR, {allowLoop: true, allowSwitch: true}],
|
185 | // lone blocks create no scope, will ignore blocks with let/const
|
186 | 'no-lone-blocks': WARNING,
|
187 | // equivalent to jshint loopfunc
|
188 | 'no-loop-func': OFF,
|
189 | // we surely have these, don't bother with it
|
190 | 'no-magic-numbers': OFF,
|
191 | // we may use this for alignment in some places
|
192 | 'no-multi-spaces': OFF,
|
193 | // equivalent to jshint multistr, consider using es6 template strings
|
194 | 'no-multi-str': ERROR,
|
195 | // equivalent to jshint W02OFF, similar to no-extend-native
|
196 | 'no-native-reassign': [ERROR, {exceptions: ['Map', 'Set']}],
|
197 | // equivalent to jshint evil/W054
|
198 | 'no-new-func': ERROR,
|
199 | // don't use constructors for side-effects, equivalent to jshint nonew
|
200 | 'no-new': WARNING,
|
201 | // very limited uses, mostly in third_party
|
202 | 'no-new-wrappers': WARNING,
|
203 | // deprecated in ES5, but we still use it in some places
|
204 | 'no-octal-escape': WARNING,
|
205 | // deprecated in ES5, may cause unexpected behavior
|
206 | 'no-octal': WARNING,
|
207 | // treats function parameters as constants, probably too noisy ATM
|
208 | 'no-param-reassign': OFF,
|
209 | // only relevant to node code
|
210 | 'no-process-env': OFF,
|
211 | // deprecated in ES3.WARNING, equivalent to jshint proto
|
212 | 'no-proto': ERROR,
|
213 | // jshint doesn't catch this, but this is inexcusable
|
214 | 'no-redeclare': WARNING,
|
215 | // equivalent to jshint boss
|
216 | 'no-return-assign': OFF,
|
217 | // equivalent to jshint scripturl
|
218 | 'no-script-url': ERROR,
|
219 | // not in jshint, but is in jslint, and is almost certainly a mistake
|
220 | 'no-self-compare': WARNING,
|
221 | // there are very limited valid use-cases for this
|
222 | 'no-sequences': WARNING,
|
223 | // we're already pretty good about this, and it hides stack traces
|
224 | 'no-throw-literal': WARNING,
|
225 | // breaks on `foo && foo.bar()` expression statements, which are common
|
226 | 'no-unused-expressions': OFF,
|
227 | // disallow unnecessary .call() and .apply()
|
228 | 'no-useless-call': WARNING,
|
229 | // disallow concatenating string literals
|
230 | 'no-useless-concat': WARNING,
|
231 | // this has valid use-cases, eg. to circumvent no-unused-expressions
|
232 | 'no-void': OFF,
|
233 | // this journey is 1% finished (allow TODO comments)
|
234 | 'no-warning-comments': OFF,
|
235 | // equivalent to jshint withstmt
|
236 | 'no-with': OFF,
|
237 | // require radix argument in parseInt, we do this in most places already
|
238 | 'radix': WARNING,
|
239 | // we don't do this/care about this
|
240 | 'vars-on-top': OFF,
|
241 | // equivalent to jshint immed
|
242 | 'wrap-iife': OFF,
|
243 | // probably too noisy ATM
|
244 | 'yoda': OFF,
|
245 |
|
246 | // Strict Mode <http://eslint.org/docs/rules/#strict-mode>
|
247 | // jshint wasn't checking this, and the compiler should add this anyways
|
248 | 'strict': OFF,
|
249 |
|
250 | // Variables <http://eslint.org/docs/rules/#variables>
|
251 | // we don't do this/care about this
|
252 | 'init-declarations': OFF,
|
253 | // equivalent to jshint W002, catches an IE8 bug
|
254 | 'no-catch-shadow': ERROR,
|
255 | // equivalent to jshint W051, is a strict mode violation
|
256 | 'no-delete-var': ERROR,
|
257 | // we should avoid labels anyways
|
258 | 'no-label-var': WARNING,
|
259 | // redefining undefined, NaN, Infinity, arguments, and eval is bad, mkay?
|
260 | 'no-shadow-restricted-names': WARNING,
|
261 | // a definite code-smell, but probably too noisy
|
262 | 'no-shadow': OFF,
|
263 | // it's nice to be explicit sometimes: `let foo = undefined;`
|
264 | 'no-undef-init': OFF,
|
265 | // equivalent to jshint undef, turned into an error in getConfig
|
266 | 'no-undef': WARNING,
|
267 | // using undefined is safe because we enforce no-shadow-restricted-names
|
268 | 'no-undefined': OFF,
|
269 | // equivalent to jshint unused
|
270 | 'no-unused-vars': [WARNING, {args: 'none'}],
|
271 | // too noisy
|
272 | 'no-use-before-define': OFF,
|
273 |
|
274 | // Node.js <http://eslint.org/docs/rules/#nodejs>
|
275 | // TODO: turn some of these on in places where we lint node code
|
276 | 'callback-return': OFF,
|
277 | 'global-require': OFF,
|
278 | 'handle-callback-err': OFF,
|
279 | 'no-mixed-requires': OFF,
|
280 | 'no-new-require': OFF,
|
281 | 'no-path-concat': OFF,
|
282 | 'no-process-exit': OFF,
|
283 | 'no-restricted-modules': OFF,
|
284 | 'no-sync': OFF,
|
285 |
|
286 | // Stylistic Issues <http://eslint.org/docs/rules/#stylistic-issues>
|
287 | // See also: https://our.intern.facebook.com/intern/dex/style-guide/
|
288 | 'array-bracket-spacing': WARNING,
|
289 | // TODO: enable this with consensus on single line blocks
|
290 | 'block-spacing': OFF,
|
291 | 'brace-style': [WARNING, '1tbs', {allowSingleLine: true}],
|
292 | // too noisy at the moment, and jshint didn't check it
|
293 | 'camelcase': [OFF, {properties: 'always'}],
|
294 | 'comma-spacing': [WARNING, {before: false, after: true}],
|
295 | // jshint had laxcomma, but that was against our style guide
|
296 | 'comma-style': [WARNING, 'last'],
|
297 | 'computed-property-spacing': [WARNING, 'never'],
|
298 | // we may use more contextually relevant names for this than self
|
299 | 'consistent-this': [OFF, 'self'],
|
300 | // should be handled by a generic TXT linter instead
|
301 | 'eol-last': OFF,
|
302 | 'func-names': OFF,
|
303 | // too noisy ATM
|
304 | 'func-style': [OFF, 'declaration'],
|
305 | // no way we could enforce min/max lengths or patterns for vars
|
306 | 'id-length': OFF,
|
307 | 'id-match': OFF,
|
308 | // we weren't enforcing this with jshint, so erroring would be too noisy
|
309 | 'indent': [WARNING, 2, {SwitchCase: 1}],
|
310 | // we use single quotes for JS literals, double quotes for JSX literals
|
311 | 'jsx-quotes': [WARNING, 'prefer-double'],
|
312 | // we may use extra spaces for alignment
|
313 | 'key-spacing': [OFF, {beforeColon: false, afterColon: true}],
|
314 | 'keyword-spacing': [WARNING],
|
315 | 'lines-around-comment': OFF,
|
316 | // should be handled by a generic TXT linter instead
|
317 | 'linebreak-style': [OFF, 'unix'],
|
318 | 'max-depth': OFF,
|
319 | 'max-len': [WARNING, 120, 2,
|
320 | {'ignorePattern': maxLenIgnorePattern},
|
321 | ],
|
322 | 'max-nested-callbacks': OFF,
|
323 | 'max-params': OFF,
|
324 | 'max-statements': OFF,
|
325 | // https://facebook.com/groups/995898333776940/1027358627297577
|
326 | 'new-cap': OFF,
|
327 | // equivalent to jshint W058
|
328 | 'new-parens': ERROR,
|
329 | 'newline-after-var': OFF,
|
330 | 'no-array-constructor': ERROR,
|
331 | 'no-bitwise': WARNING,
|
332 | 'no-continue': OFF,
|
333 | 'no-inline-comments': OFF,
|
334 | // doesn't play well with `if (__DEV__) {}`
|
335 | 'no-lonely-if': OFF,
|
336 | // stopgap, irrelevant if we can eventually turn `indent` on to error
|
337 | 'no-mixed-spaces-and-tabs': ERROR,
|
338 | // don't care
|
339 | 'no-multiple-empty-lines': OFF,
|
340 | 'no-negated-condition': OFF,
|
341 | // we do this a bunch of places, and it's less bad with proper indentation
|
342 | 'no-nested-ternary': OFF,
|
343 | // similar to FacebookWebJSLintLinter's checkPhpStyleArray
|
344 | 'no-new-object': WARNING,
|
345 | 'no-plusplus': OFF,
|
346 | 'no-restricted-syntax': OFF,
|
347 | 'no-spaced-func': WARNING,
|
348 | 'no-ternary': OFF,
|
349 | // should be handled by a generic TXT linter instead
|
350 | 'no-trailing-spaces': OFF,
|
351 | // we use this for private/protected identifiers
|
352 | 'no-underscore-dangle': OFF,
|
353 | // disallow `let isYes = answer === 1 ? true : false;`
|
354 | 'no-unneeded-ternary': WARNING,
|
355 | // too noisy ATM
|
356 | 'object-curly-spacing': OFF,
|
357 | // makes indentation warnings clearer
|
358 | 'one-var': [WARNING, {initialized: 'never'}],
|
359 | // prefer `x += 4` over `x = x + 4`
|
360 | 'operator-assignment': [WARNING, 'always'],
|
361 | // equivalent to jshint laxbreak
|
362 | 'operator-linebreak': OFF,
|
363 | 'padded-blocks': OFF,
|
364 | // probably too noisy on pre-ES5 code
|
365 | 'quote-props': [OFF, 'as-needed'],
|
366 | 'quotes': [WARNING, 'single', 'avoid-escape'],
|
367 | 'require-jsdoc': OFF,
|
368 | 'semi-spacing': [WARNING, {before: false, after: true}],
|
369 | // equivalent to jshint asi/W032
|
370 | 'semi': [WARNING, 'always'],
|
371 | 'sort-vars': OFF,
|
372 | // require `if () {` instead of `if (){`
|
373 | 'space-before-blocks': [WARNING, 'always'],
|
374 | // require `function foo()` instead of `function foo ()`
|
375 | 'space-before-function-paren': [
|
376 | WARNING,
|
377 | {anonymous: 'never', named: 'never'},
|
378 | ],
|
379 | // incompatible with our legacy inline type annotations
|
380 | 'space-in-parens': [OFF, 'never'],
|
381 | 'space-infix-ops': [WARNING, {int32Hint: true}],
|
382 | 'space-unary-ops': [WARNING, {words: true, nonwords: false}],
|
383 | // TODO: Figure out a way to do this that doesn't break typechecks
|
384 | // or wait for https://github.com/eslint/eslint/issues/2897
|
385 | 'spaced-comment':
|
386 | [OFF, 'always', {exceptions: ['jshint', 'jslint', 'eslint', 'global']}],
|
387 | 'wrap-regex': OFF,
|
388 |
|
389 | // ECMAScript 6 <http://eslint.org/docs/rules/#ecmascript-6>
|
390 | 'arrow-body-style': OFF,
|
391 | // Forked to fb-www/arrow-parens to fix issues with flow and add fixer
|
392 | 'arrow-parens': OFF,
|
393 | // tbgs finds *very few* places where we don't put spaces around =>
|
394 | 'arrow-spacing': [WARNING, {before: true, after: true}],
|
395 | // violation of the ES6 spec, won't transform
|
396 | 'constructor-super': ERROR,
|
397 | // https://github.com/babel/babel-eslint#known-issues
|
398 | 'generator-star-spacing': OFF,
|
399 | 'no-class-assign': WARNING,
|
400 | 'no-confusing-arrow': OFF,
|
401 | // this is a runtime error
|
402 | 'no-const-assign': ERROR,
|
403 | 'no-dupe-class-members': ERROR,
|
404 | // violation of the ES6 spec, won't transform, `this` is part of the TDZ
|
405 | 'no-this-before-super': ERROR,
|
406 | // we have way too much ES3 & ES5 code
|
407 | 'no-var': OFF,
|
408 | 'object-shorthand': OFF,
|
409 | 'prefer-const': OFF,
|
410 | 'prefer-spread': OFF,
|
411 | // we don't support/polyfill this yet
|
412 | 'prefer-reflect': OFF,
|
413 | 'prefer-template': OFF,
|
414 | // there are legitimate use-cases for an empty generator
|
415 | 'require-yield': OFF,
|
416 |
|
417 | // eslint-plugin-babel <https://github.com/babel/eslint-plugin-babel>
|
418 | 'babel/generator-star-spacing': OFF,
|
419 | 'babel/new-cap': OFF,
|
420 | 'babel/array-bracket-spacing': OFF,
|
421 | 'babel/object-curly-spacing': OFF,
|
422 | 'babel/object-shorthand': OFF,
|
423 | 'babel/arrow-parens': OFF,
|
424 | 'babel/no-await-in-loop': OFF,
|
425 | 'babel/flow-object-type': [WARNING, 'comma'],
|
426 |
|
427 | // eslint-plugin-react <https://github.com/yannickcr/eslint-plugin-react>
|
428 | // TODO: We're being extremely conservative here as we roll out eslint on
|
429 | // www. As we finish rollout, we can turn on more of these, and replace
|
430 | // some legacy regex rules in the process.
|
431 | 'react/display-name': OFF,
|
432 | 'react/forbid-prop-types': OFF,
|
433 | 'react/jsx-boolean-value': OFF,
|
434 | 'react/jsx-closing-bracket-location': OFF,
|
435 | 'react/jsx-curly-spacing': OFF,
|
436 | 'react/jsx-equals-spacing': WARNING,
|
437 | 'react/jsx-filename-extension': OFF,
|
438 | 'react/jsx-first-prop-new-line': OFF,
|
439 | 'react/jsx-handler-names': OFF,
|
440 | 'react/jsx-indent': OFF,
|
441 | 'react/jsx-indent-props': OFF,
|
442 | 'react/jsx-key': OFF,
|
443 | 'react/jsx-max-props-per-line': OFF,
|
444 | 'react/jsx-no-bind': OFF,
|
445 | 'react/jsx-no-duplicate-props': ERROR,
|
446 | 'react/jsx-no-literals': OFF,
|
447 | 'react/jsx-no-target-blank': OFF,
|
448 | 'react/jsx-no-undef': ERROR,
|
449 | 'react/jsx-pascal-case': OFF,
|
450 | 'react/jsx-sort-props': OFF,
|
451 | 'react/jsx-space-before-closing': OFF,
|
452 | // forked to fb-www/jsx-uses-react
|
453 | 'react/jsx-uses-react': OFF,
|
454 | 'react/jsx-uses-vars': ERROR,
|
455 | 'react/no-comment-textnodes': OFF,
|
456 | 'react/no-danger': OFF,
|
457 | 'react/no-deprecated': OFF,
|
458 | 'react/no-did-mount-set-state': OFF,
|
459 | 'react/no-did-update-set-state': OFF,
|
460 | 'react/no-direct-mutation-state': OFF,
|
461 | 'react/no-is-mounted': WARNING,
|
462 | 'react/no-multi-comp': OFF,
|
463 | 'react/no-render-return-value': OFF,
|
464 | 'react/no-set-state': OFF,
|
465 | 'react/no-string-refs': OFF,
|
466 | 'react/no-unknown-property': OFF,
|
467 | 'react/prefer-es6-class': OFF,
|
468 | 'react/prefer-stateless-function': OFF,
|
469 | 'react/prop-types': OFF,
|
470 | // forked to fb-www/react-in-jsx-scope
|
471 | 'react/react-in-jsx-scope': OFF,
|
472 | 'react/require-extension': OFF,
|
473 | 'react/require-optimization': OFF,
|
474 | 'react/require-render-return': OFF,
|
475 | 'react/self-closing-comp': OFF,
|
476 | 'react/sort-comp': OFF,
|
477 | 'react/sort-prop-types': OFF,
|
478 | 'react/wrap-multilines': OFF,
|
479 |
|
480 | // eslint-plugin-flow-vars
|
481 | // These don't actually result in warnings. Enabling them ensures they run
|
482 | // and mark variables as used, avoiding false positives with Flow
|
483 | // annotations.
|
484 | 'flow-vars/define-flow-type': WARNING,
|
485 | 'flow-vars/use-flow-type': WARNING,
|
486 | },
|
487 |
|
488 | // Defines a basic set of globals
|
489 | env: {
|
490 | browser: true,
|
491 | es6: true,
|
492 | },
|
493 |
|
494 | // The jshint code had more globals, which may have had something to do with
|
495 | // machine-generated code. I couldn't find references with tbgs.
|
496 | //
|
497 | // Values of true mean the global may be modified. Values of false represent
|
498 | // constants.
|
499 | globals: {
|
500 | __DEV__: true,
|
501 | // Haste-defined variables
|
502 | require: true,
|
503 | requireDynamic: true,
|
504 | requireLazy: true,
|
505 | // more haste variables are defined in getConfig for modules
|
506 |
|
507 | // Workarounds for https://github.com/babel/babel-eslint/issues/130
|
508 | // no-undef errors incorrectly on these global flow types
|
509 | // https://fburl.com/flow-react-defs
|
510 | ReactComponent: false,
|
511 | ReactClass: false,
|
512 | ReactElement: false,
|
513 | ReactPropsCheckType: false,
|
514 | ReactPropsChainableTypeChecker: false,
|
515 | ReactPropTypes: false,
|
516 | SyntheticEvent: false,
|
517 | SyntheticClipboardEvent: false,
|
518 | SyntheticCompositionEvent: false,
|
519 | SyntheticInputEvent: false,
|
520 | SyntheticUIEvent: false,
|
521 | SyntheticFocusEvent: false,
|
522 | SyntheticKeyboardEvent: false,
|
523 | SyntheticMouseEvent: false,
|
524 | SyntheticDragEvent: false,
|
525 | SyntheticWheelEvent: false,
|
526 | SyntheticTouchEvent: false,
|
527 | // a bunch of types extracted from http://git.io/vOtv9
|
528 | // there's a bunch of overlap with browser globals, so we try to avoid
|
529 | // redefining some of those.
|
530 | $Either: false,
|
531 | $All: false,
|
532 | $Tuple: false,
|
533 | $Supertype: false,
|
534 | $Subtype: false,
|
535 | $Shape: false,
|
536 | $Diff: false,
|
537 | $Keys: false,
|
538 | $Enum: false,
|
539 | $Exports: false,
|
540 | Class: false,
|
541 | function: false,
|
542 | Iterable: false,
|
543 | // suppress types
|
544 | $FlowIssue: false,
|
545 | $FlowFixMe: false,
|
546 | $FixMe: false,
|
547 | // https://fburl.com/flow-core-defs
|
548 | Iterator: false,
|
549 | IteratorResult: false,
|
550 | $await: false,
|
551 | ArrayBufferView: false,
|
552 | // https://fburl.com/flow-fb-defs
|
553 | FbtResult: false,
|
554 | $jsx: false,
|
555 | FBID: false,
|
556 | AdAccountID: false,
|
557 | UID: false,
|
558 | ReactNode: false,
|
559 | Fbt: false,
|
560 | // https://fburl.com/flow-liverail-defs
|
561 | LRID: false,
|
562 | // https://fburl.com/flow-powereditor-def
|
563 | UkiAccount: false,
|
564 | UkiAdgroup: false,
|
565 | UkiCampaign: false,
|
566 | UkiCampaignGroup: false,
|
567 | // some of this maybe should be handled by the npm globals module, but it
|
568 | // doesn't have proper WebRTC support yet
|
569 | // https://fburl.com/flow-webrtc-defs
|
570 | RTCConfiguration: false,
|
571 | RTCIceServer: false,
|
572 | RTCOfferOptions: false,
|
573 | RTCStatsReport: false,
|
574 | RTCStatsCallback: false,
|
575 | RTCPeerConnection: false,
|
576 | RTCPeerConnectionErrorCallback: false,
|
577 | RTCSessionDescription: false,
|
578 | RTCSessionDescriptionInit: false,
|
579 | RTCSessionDescriptionCallback: false,
|
580 | RTCIceCandidate: false,
|
581 | RTCIceCandidateInit: false,
|
582 | RTCPeerConnectionIceEvent: false,
|
583 | RTCPeerConnectionIceEventInit: false,
|
584 | RTCDataChannel: false,
|
585 | RTCDataChannelInit: false,
|
586 | RTCDataChannelEvent: false,
|
587 | RTCDataChannelEventInit: false,
|
588 | },
|
589 | };
|
590 | }
|
591 |
|
592 | // Override some rules for open source. Due to the way we apply our configuation
|
593 | // internally, these are effectively part of the same configuration we apply.
|
594 | var config = getBaseConfig();
|
595 | var extendedConfig = {
|
596 | env: {
|
597 | // Enable these blindly because we can't make a per-file decision about this.
|
598 | node: true,
|
599 | jest: true,
|
600 | jasmine: true,
|
601 | },
|
602 | rules: {
|
603 | // just turned into an error here since we almost always do that anyway.
|
604 | 'no-undef': ERROR,
|
605 |
|
606 | // Re-enable some forked rules. Good enough for open source
|
607 | 'comma-dangle': [WARNING, 'always-multiline'],
|
608 |
|
609 | 'react/jsx-uses-react': ERROR,
|
610 | 'react/react-in-jsx-scope': ERROR,
|
611 |
|
612 | },
|
613 | };
|
614 |
|
615 | Object.keys(extendedConfig).forEach((key) => {
|
616 | config[key] = Object.assign(config[key], extendedConfig[key]);
|
617 | });
|
618 |
|
619 | module.exports = config;
|