index.js 7.9 KB
Newer Older
1
2
3
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
Sophie Alpert's avatar
Sophie Alpert committed
4
5
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
6
7
 */

8
9
'use strict';

10
11
// Inspired by https://github.com/airbnb/javascript but less opinionated.

Brian Ng's avatar
Brian Ng committed
12
// We use eslint-loader so even warnings are very visible.
13
14
15
16
17
18
// 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.

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
// 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',
];

85
86
87
module.exports = {
  root: true,

88
89
  parser: 'babel-eslint',

90
  plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],
91
92

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

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

  rules: {
    // http://eslint.org/docs/rules/
112
113
114
115
116
117
118
    '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',
119
    'no-cond-assign': ['warn', 'except-parens'],
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
    '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
140
    'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
141
142
    'no-lone-blocks': 'warn',
    'no-loop-func': 'warn',
143
144
145
146
147
148
149
150
151
152
153
154
    'no-mixed-operators': [
      'warn',
      {
        groups: [
          ['&', '|', '^', '~', '<<', '>>', '>>>'],
          ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
          ['&&', '||'],
          ['in', 'instanceof'],
        ],
        allowSamePrecedence: false,
      },
    ],
155
156
157
158
159
160
161
162
163
164
165
166
    '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
167
    'no-restricted-syntax': ['warn', 'WithStatement'],
168
169
170
171
172
173
    '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
174
    'no-template-curly-in-string': 'warn',
175
176
    'no-this-before-super': 'warn',
    'no-throw-literal': 'warn',
177
    'no-undef': 'error',
178
    'no-restricted-globals': ['error'].concat(restrictedGlobals),
179
180
    'no-unexpected-multiline': 'warn',
    'no-unreachable': 'warn',
181
182
183
184
185
    'no-unused-expressions': [
      'warn',
      {
        allowShortCircuit: true,
        allowTernary: true,
186
        allowTaggedTemplates: true,
187
188
      },
    ],
189
    'no-unused-labels': 'warn',
190
191
192
193
194
195
196
    'no-unused-vars': [
      'warn',
      {
        args: 'none',
        ignoreRestSiblings: true,
      },
    ],
197
198
199
200
201
202
203
204
    'no-use-before-define': [
      'warn',
      {
        functions: false,
        classes: false,
        variables: false,
      },
    ],
205
206
207
208
    'no-useless-computed-key': 'warn',
    'no-useless-concat': 'warn',
    'no-useless-constructor': 'warn',
    'no-useless-escape': 'warn',
209
210
211
212
213
214
215
216
    'no-useless-rename': [
      'warn',
      {
        ignoreDestructuring: false,
        ignoreImport: false,
        ignoreExport: false,
      },
    ],
217
218
219
220
221
222
223
224
225
    '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',
226
227
    'no-restricted-properties': [
      'error',
228
229
230
231
232
233
      {
        object: 'require',
        property: 'ensure',
        message:
          'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
      },
234
235
236
      {
        object: 'System',
        property: 'import',
237
238
        message:
          'Please use import() instead. More info: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
239
240
      },
    ],
241

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

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

    // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
270
271
272
    'jsx-a11y/accessible-emoji': 'warn',
    'jsx-a11y/alt-text': 'warn',
    'jsx-a11y/anchor-has-content': 'warn',
273
274
275
276
277
278
    'jsx-a11y/anchor-is-valid': [
      'warn',
      {
        aspects: ['noHref', 'invalidHref'],
      },
    ],
279
280
281
    'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
    'jsx-a11y/aria-props': 'warn',
    'jsx-a11y/aria-proptypes': 'warn',
282
    'jsx-a11y/aria-role': 'warn',
283
284
285
    'jsx-a11y/aria-unsupported-elements': 'warn',
    'jsx-a11y/heading-has-content': 'warn',
    'jsx-a11y/iframe-has-title': 'warn',
286
    'jsx-a11y/img-redundant-alt': 'warn',
287
    'jsx-a11y/no-access-key': 'warn',
288
289
290
291
292
    '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',
293

294
295
    // https://github.com/gajus/eslint-plugin-flowtype
    'flowtype/define-flow-type': 'warn',
296
    'flowtype/require-valid-file-annotation': 'warn',
297
298
    'flowtype/use-flow-type': 'warn',
  },
299
};