index.js 8.13 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
113
  },

  rules: {
    // http://eslint.org/docs/rules/
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
    '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
142
    'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
143
144
    'no-lone-blocks': 'warn',
    'no-loop-func': 'warn',
145
146
147
148
149
150
151
152
153
154
155
156
    'no-mixed-operators': [
      'warn',
      {
        groups: [
          ['&', '|', '^', '~', '<<', '>>', '>>>'],
          ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
          ['&&', '||'],
          ['in', 'instanceof'],
        ],
        allowSamePrecedence: false,
      },
    ],
157
158
159
160
161
162
163
164
165
166
167
168
    '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
169
    'no-restricted-syntax': ['warn', 'WithStatement'],
170
171
172
173
174
175
    '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
176
    'no-template-curly-in-string': 'warn',
177
178
    'no-this-before-super': 'warn',
    'no-throw-literal': 'warn',
179
    'no-undef': 'error',
180
    'no-restricted-globals': ['error'].concat(restrictedGlobals),
181
182
    'no-unexpected-multiline': 'warn',
    'no-unreachable': 'warn',
183
184
185
186
187
188
189
    'no-unused-expressions': [
      'warn',
      {
        allowShortCircuit: true,
        allowTernary: true,
      },
    ],
190
    'no-unused-labels': 'warn',
191
192
193
194
195
196
197
    'no-unused-vars': [
      'warn',
      {
        args: 'none',
        ignoreRestSiblings: true,
      },
    ],
198
199
200
201
202
203
204
205
    'no-use-before-define': [
      'warn',
      {
        functions: false,
        classes: false,
        variables: false,
      },
    ],
206
207
208
209
    'no-useless-computed-key': 'warn',
    'no-useless-concat': 'warn',
    'no-useless-constructor': 'warn',
    'no-useless-escape': 'warn',
210
211
212
213
214
215
216
217
    'no-useless-rename': [
      'warn',
      {
        ignoreDestructuring: false,
        ignoreImport: false,
        ignoreExport: false,
      },
    ],
218
219
220
221
222
223
224
225
226
    'no-with': 'warn',
    'no-whitespace-before-property': 'warn',
    radix: 'warn',
    'require-yield': 'warn',
    'rest-spread-spacing': ['warn', 'never'],
    strict: ['warn', 'never'],
    'unicode-bom': ['warn', 'never'],
    'use-isnan': 'warn',
    'valid-typeof': 'warn',
227
228
    'no-restricted-properties': [
      'error',
229
230
231
232
233
      // TODO: reenable once import() is no longer slow.
      // https://github.com/facebookincubator/create-react-app/issues/2176
      // {
      //   object: 'require',
      //   property: 'ensure',
234
      //   message: 'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
235
      // },
236
237
238
      {
        object: 'System',
        property: 'import',
239
        message: 'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
240
241
      },
    ],
242

Dan Abramov's avatar
Dan Abramov committed
243
    // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
Dan Abramov's avatar
Dan Abramov committed
244
245
    'import/first': 'error',
    'import/no-amd': 'error',
246
    'import/no-webpack-loader-syntax': 'error',
247
248

    // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
Dan Abramov's avatar
Dan Abramov committed
249
    'react/jsx-no-comment-textnodes': 'warn',
250
    'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }],
Dan Abramov's avatar
Dan Abramov committed
251
    'react/jsx-no-target-blank': 'warn',
252
    'react/jsx-no-undef': 'error',
253
254
255
256
257
258
259
    'react/jsx-pascal-case': [
      'warn',
      {
        allowAllCaps: true,
        ignore: [],
      },
    ],
260
261
    'react/jsx-uses-react': 'warn',
    'react/jsx-uses-vars': 'warn',
262
    'react/no-danger-with-children': 'warn',
263
264
265
    'react/no-deprecated': 'warn',
    'react/no-direct-mutation-state': 'warn',
    'react/no-is-mounted': 'warn',
266
    'react/react-in-jsx-scope': 'error',
Dan Abramov's avatar
Dan Abramov committed
267
    'react/require-render-return': 'error',
268
    'react/style-prop-object': 'warn',
269
270

    // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
271
272
273
274
275
276
    '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',
277
    'jsx-a11y/aria-role': 'warn',
278
279
280
281
    'jsx-a11y/aria-unsupported-elements': 'warn',
    'jsx-a11y/heading-has-content': 'warn',
    'jsx-a11y/href-no-hash': 'warn',
    'jsx-a11y/iframe-has-title': 'warn',
282
    'jsx-a11y/img-redundant-alt': 'warn',
283
    'jsx-a11y/no-access-key': 'warn',
284
285
286
287
288
    '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',
289

290
291
    // https://github.com/gajus/eslint-plugin-flowtype
    'flowtype/define-flow-type': 'warn',
292
293
    // TODO: Reenable once https://github.com/gajus/eslint-plugin-flowtype/issues/165 is fixed
    //'flowtype/require-valid-file-annotation': 'warn',
294
295
    'flowtype/use-flow-type': 'warn',
  },
296
};