index.js 9.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
/**
 * Copyright (c) 2015-present, 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.
 */

10
11
'use strict';

12
13
// Inspired by https://github.com/airbnb/javascript but less opinionated.

Brian Ng's avatar
Brian Ng committed
14
// We use eslint-loader so even warnings are very visible.
15
16
17
18
19
20
// This is why we only use "WARNING" level for potential errors,
// and we don't use "ERROR" level at all.

// In the future, we might create a separate list of rules for production.
// It would probably be more strict.

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
// The ESLint browser environment defines all browser globals as valid,
// even though most people don't know some of them exist (e.g. `name` or `status`).
// This is dangerous as it hides accidentally undefined variables.
// We blacklist the globals that we deem potentially confusing.
// To use them, explicitly reference them, e.g. `window.name` or `window.status`.
var restrictedGlobals = [
  'addEventListener',
  'blur',
  'close',
  'closed',
  'confirm',
  'defaultStatus',
  'defaultstatus',
  'event',
  'external',
  'find',
  'focus',
  'frameElement',
  'frames',
  'history',
  'innerHeight',
  'innerWidth',
  'length',
  'location',
  'locationbar',
  'menubar',
  'moveBy',
  'moveTo',
  'name',
  'onblur',
  'onerror',
  'onfocus',
  'onload',
  'onresize',
  'onunload',
  'open',
  'opener',
  'opera',
  'outerHeight',
  'outerWidth',
  'pageXOffset',
  'pageYOffset',
  'parent',
  'print',
  'removeEventListener',
  'resizeBy',
  'resizeTo',
  'screen',
  'screenLeft',
  'screenTop',
  'screenX',
  'screenY',
  'scroll',
  'scrollbars',
  'scrollBy',
  'scrollTo',
  'scrollX',
  'scrollY',
  'self',
  'status',
  'statusbar',
  'stop',
  'toolbar',
  'top',
];

87
88
89
module.exports = {
  root: true,

90
91
  parser: 'babel-eslint',

92
  plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],
93
94

  env: {
95
    browser: true,
96
    commonjs: true,
97
    es6: true,
Christoph Pojer's avatar
Christoph Pojer committed
98
    jest: true,
99
    node: true,
100
101
102
103
104
105
106
107
  },

  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      generators: true,
108
109
      experimentalObjectRestSpread: true,
    },
110
111
112
  },

  settings: {
113
    'import/ignore': ['node_modules'],
114
115
116
    'import/extensions': ['.js'],
    'import/resolver': {
      node: {
117
118
119
        extensions: ['.js', '.json'],
      },
    },
120
121
122
123
  },

  rules: {
    // http://eslint.org/docs/rules/
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
    'array-callback-return': 'warn',
    'default-case': ['warn', { commentPattern: '^no default$' }],
    'dot-location': ['warn', 'property'],
    eqeqeq: ['warn', 'allow-null'],
    'new-parens': 'warn',
    'no-array-constructor': 'warn',
    'no-caller': 'warn',
    'no-cond-assign': ['warn', 'always'],
    'no-const-assign': 'warn',
    'no-control-regex': 'warn',
    'no-delete-var': 'warn',
    'no-dupe-args': 'warn',
    'no-dupe-class-members': 'warn',
    'no-dupe-keys': 'warn',
    'no-duplicate-case': 'warn',
    'no-empty-character-class': 'warn',
    'no-empty-pattern': 'warn',
    'no-eval': 'warn',
    'no-ex-assign': 'warn',
    'no-extend-native': 'warn',
    'no-extra-bind': 'warn',
    'no-extra-label': 'warn',
    'no-fallthrough': 'warn',
    'no-func-assign': 'warn',
    'no-implied-eval': 'warn',
    'no-invalid-regexp': 'warn',
    'no-iterator': 'warn',
    'no-label-var': 'warn',
anilreddykatta's avatar
anilreddykatta committed
152
    'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
153
154
    'no-lone-blocks': 'warn',
    'no-loop-func': 'warn',
155
156
157
158
159
160
161
162
163
164
165
166
    'no-mixed-operators': [
      'warn',
      {
        groups: [
          ['&', '|', '^', '~', '<<', '>>', '>>>'],
          ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
          ['&&', '||'],
          ['in', 'instanceof'],
        ],
        allowSamePrecedence: false,
      },
    ],
167
168
169
170
171
172
173
174
175
176
177
178
    'no-multi-str': 'warn',
    'no-native-reassign': 'warn',
    'no-negated-in-lhs': 'warn',
    'no-new-func': 'warn',
    'no-new-object': 'warn',
    'no-new-symbol': 'warn',
    'no-new-wrappers': 'warn',
    'no-obj-calls': 'warn',
    'no-octal': 'warn',
    'no-octal-escape': 'warn',
    'no-redeclare': 'warn',
    'no-regex-spaces': 'warn',
anilreddykatta's avatar
anilreddykatta committed
179
    'no-restricted-syntax': ['warn', 'WithStatement'],
180
181
182
183
184
185
    'no-script-url': 'warn',
    'no-self-assign': 'warn',
    'no-self-compare': 'warn',
    'no-sequences': 'warn',
    'no-shadow-restricted-names': 'warn',
    'no-sparse-arrays': 'warn',
Dan Abramov's avatar
Dan Abramov committed
186
    'no-template-curly-in-string': 'warn',
187
188
    'no-this-before-super': 'warn',
    'no-throw-literal': 'warn',
189
    'no-undef': 'error',
190
    'no-restricted-globals': ['error'].concat(restrictedGlobals),
191
192
    'no-unexpected-multiline': 'warn',
    'no-unreachable': 'warn',
193
194
195
196
197
198
199
    'no-unused-expressions': [
      'warn',
      {
        allowShortCircuit: true,
        allowTernary: true,
      },
    ],
200
    'no-unused-labels': 'warn',
201
202
203
204
205
206
207
    'no-unused-vars': [
      'warn',
      {
        args: 'none',
        ignoreRestSiblings: true,
      },
    ],
208
209
210
211
212
    'no-use-before-define': ['warn', 'nofunc'],
    'no-useless-computed-key': 'warn',
    'no-useless-concat': 'warn',
    'no-useless-constructor': 'warn',
    'no-useless-escape': 'warn',
213
214
215
216
217
218
219
220
    'no-useless-rename': [
      'warn',
      {
        ignoreDestructuring: false,
        ignoreImport: false,
        ignoreExport: false,
      },
    ],
221
222
223
224
225
226
227
228
229
230
    'no-with': 'warn',
    'no-whitespace-before-property': 'warn',
    'operator-assignment': ['warn', 'always'],
    radix: 'warn',
    'require-yield': 'warn',
    'rest-spread-spacing': ['warn', 'never'],
    strict: ['warn', 'never'],
    'unicode-bom': ['warn', 'never'],
    'use-isnan': 'warn',
    'valid-typeof': 'warn',
231
232
233
234
235
236
237
238
239
240
241
242
243
    'no-restricted-properties': [
      'error',
      {
        object: 'require',
        property: 'ensure',
        message: 'Please use import() instead. More info: https://webpack.js.org/guides/code-splitting-import/#dynamic-import',
      },
      {
        object: 'System',
        property: 'import',
        message: 'Please use import() instead. More info: https://webpack.js.org/guides/code-splitting-import/#dynamic-import',
      },
    ],
244
245
246

    // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/

247
248
249
250
251
252
253
254
255
256
    // TODO: import rules are temporarily disabled because they don't play well
    // with how eslint-loader only checks the file you change. So if module A
    // imports module B, and B is missing a default export, the linter will
    // record this as an issue in module A. Now if you fix module B, the linter
    // will not be aware that it needs to re-lint A as well, so the error
    // will stay until the next restart, which is really confusing.

    // This is probably fixable with a patch to eslint-loader.
    // When file A is saved, we want to invalidate all files that import it
    // *and* that currently have lint errors. This should fix the problem.
257
258
259
    // (As an exception, import/no-webpack-loader-syntax can be enabled already
    // because it doesn't depend on whether the file exists, so this issue
    // doesn't apply to it.)
260

261
262
263
264
265
266
267
268
269
270
    // 'import/default': 'warn',
    // 'import/export': 'warn',
    // 'import/named': 'warn',
    // 'import/namespace': 'warn',
    // 'import/no-amd': 'warn',
    // 'import/no-duplicates': 'warn',
    // 'import/no-extraneous-dependencies': 'warn',
    // 'import/no-named-as-default': 'warn',
    // 'import/no-named-as-default-member': 'warn',
    // 'import/no-unresolved': ['warn', { commonjs: true }],
271
272
273
    // We don't support configuring Webpack using import source strings, so this
    // is always an error.
    'import/no-webpack-loader-syntax': 'error',
274
275

    // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
276
    'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }],
277
    'react/jsx-no-undef': 'error',
278
279
280
281
282
283
284
    'react/jsx-pascal-case': [
      'warn',
      {
        allowAllCaps: true,
        ignore: [],
      },
    ],
285
286
    'react/jsx-uses-react': 'warn',
    'react/jsx-uses-vars': 'warn',
287
    'react/no-danger-with-children': 'warn',
288
289
290
    'react/no-deprecated': 'warn',
    'react/no-direct-mutation-state': 'warn',
    'react/no-is-mounted': 'warn',
291
    'react/react-in-jsx-scope': 'error',
292
    'react/require-render-return': 'warn',
293
    'react/style-prop-object': 'warn',
294
295

    // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
296
297
298
299
300
301
    'jsx-a11y/accessible-emoji': 'warn',
    'jsx-a11y/alt-text': 'warn',
    'jsx-a11y/anchor-has-content': 'warn',
    'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
    'jsx-a11y/aria-props': 'warn',
    'jsx-a11y/aria-proptypes': 'warn',
302
    'jsx-a11y/aria-role': 'warn',
303
304
305
306
    'jsx-a11y/aria-unsupported-elements': 'warn',
    'jsx-a11y/heading-has-content': 'warn',
    'jsx-a11y/href-no-hash': 'warn',
    'jsx-a11y/iframe-has-title': 'warn',
307
    'jsx-a11y/img-redundant-alt': 'warn',
308
    'jsx-a11y/no-access-key': 'warn',
309
310
311
312
313
    'jsx-a11y/no-distracting-elements': 'warn',
    'jsx-a11y/no-redundant-roles': 'warn',
    'jsx-a11y/role-has-required-aria-props': 'warn',
    'jsx-a11y/role-supports-aria-props': 'warn',
    'jsx-a11y/scope': 'warn',
314

315
316
317
    // https://github.com/gajus/eslint-plugin-flowtype
    'flowtype/define-flow-type': 'warn',
    'flowtype/require-valid-file-annotation': 'warn',
318
319
    'flowtype/use-flow-type': 'warn',
  },
320
};