index.js 7.16 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
// 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`.
24
var restrictedGlobals = require('confusing-browser-globals');
25

26
27
28
module.exports = {
  root: true,

29
30
  parser: 'babel-eslint',

31
  plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],
32
33

  env: {
34
    browser: true,
35
    commonjs: true,
36
    es6: true,
Christoph Pojer's avatar
Christoph Pojer committed
37
    jest: true,
38
    node: true,
39
40
41
42
43
44
45
46
  },

  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      generators: true,
47
48
      experimentalObjectRestSpread: true,
    },
49
50
51
52
  },

  rules: {
    // http://eslint.org/docs/rules/
53
54
55
56
57
58
59
    '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',
60
    'no-cond-assign': ['warn', 'except-parens'],
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    '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
81
    'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
82
83
    'no-lone-blocks': 'warn',
    'no-loop-func': 'warn',
84
85
86
87
88
89
90
91
92
93
94
95
    'no-mixed-operators': [
      'warn',
      {
        groups: [
          ['&', '|', '^', '~', '<<', '>>', '>>>'],
          ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
          ['&&', '||'],
          ['in', 'instanceof'],
        ],
        allowSamePrecedence: false,
      },
    ],
96
97
98
99
100
101
102
103
104
105
106
107
    '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
108
    'no-restricted-syntax': ['warn', 'WithStatement'],
109
110
111
112
113
114
    '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
115
    'no-template-curly-in-string': 'warn',
116
117
    'no-this-before-super': 'warn',
    'no-throw-literal': 'warn',
118
    'no-undef': 'error',
119
    'no-restricted-globals': ['error'].concat(restrictedGlobals),
120
121
    'no-unexpected-multiline': 'warn',
    'no-unreachable': 'warn',
122
    'no-unused-expressions': [
123
      'error',
124
125
126
      {
        allowShortCircuit: true,
        allowTernary: true,
127
        allowTaggedTemplates: true,
128
129
      },
    ],
130
    'no-unused-labels': 'warn',
131
132
133
    'no-unused-vars': [
      'warn',
      {
134
        args: 'all',
135
136
137
        ignoreRestSiblings: true,
      },
    ],
138
139
140
141
142
143
144
145
    'no-use-before-define': [
      'warn',
      {
        functions: false,
        classes: false,
        variables: false,
      },
    ],
146
147
148
149
    'no-useless-computed-key': 'warn',
    'no-useless-concat': 'warn',
    'no-useless-constructor': 'warn',
    'no-useless-escape': 'warn',
150
151
152
153
154
155
156
157
    'no-useless-rename': [
      'warn',
      {
        ignoreDestructuring: false,
        ignoreImport: false,
        ignoreExport: false,
      },
    ],
158
159
160
161
162
163
164
165
    'no-with': 'warn',
    'no-whitespace-before-property': 'warn',
    'require-yield': 'warn',
    'rest-spread-spacing': ['warn', 'never'],
    strict: ['warn', 'never'],
    'unicode-bom': ['warn', 'never'],
    'use-isnan': 'warn',
    'valid-typeof': 'warn',
166
167
    'no-restricted-properties': [
      'error',
168
169
170
171
      {
        object: 'require',
        property: 'ensure',
        message:
172
          'Please use import() instead. More info: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
173
      },
174
175
176
      {
        object: 'System',
        property: 'import',
177
        message:
178
          'Please use import() instead. More info: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting',
179
180
      },
    ],
181
    'getter-return': 'warn',
182

Dan Abramov's avatar
Dan Abramov committed
183
    // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
Dan Abramov's avatar
Dan Abramov committed
184
185
    'import/first': 'error',
    'import/no-amd': 'error',
186
    'import/no-webpack-loader-syntax': 'error',
187
188

    // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
Dan Abramov's avatar
Dan Abramov committed
189
    'react/jsx-no-comment-textnodes': 'warn',
190
    'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }],
Dan Abramov's avatar
Dan Abramov committed
191
    'react/jsx-no-target-blank': 'warn',
192
    'react/jsx-no-undef': 'error',
193
194
195
196
197
198
199
    'react/jsx-pascal-case': [
      'warn',
      {
        allowAllCaps: true,
        ignore: [],
      },
    ],
200
201
    'react/jsx-uses-react': 'warn',
    'react/jsx-uses-vars': 'warn',
202
    'react/no-danger-with-children': 'warn',
203
204
205
    'react/no-deprecated': 'warn',
    'react/no-direct-mutation-state': 'warn',
    'react/no-is-mounted': 'warn',
206
    'react/react-in-jsx-scope': 'error',
Dan Abramov's avatar
Dan Abramov committed
207
    'react/require-render-return': 'error',
208
    'react/style-prop-object': 'warn',
209
210

    // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
211
212
213
    'jsx-a11y/accessible-emoji': 'warn',
    'jsx-a11y/alt-text': 'warn',
    'jsx-a11y/anchor-has-content': 'warn',
214
215
216
217
218
219
    'jsx-a11y/anchor-is-valid': [
      'warn',
      {
        aspects: ['noHref', 'invalidHref'],
      },
    ],
220
221
222
    'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
    'jsx-a11y/aria-props': 'warn',
    'jsx-a11y/aria-proptypes': 'warn',
223
    'jsx-a11y/aria-role': 'warn',
224
225
226
    'jsx-a11y/aria-unsupported-elements': 'warn',
    'jsx-a11y/heading-has-content': 'warn',
    'jsx-a11y/iframe-has-title': 'warn',
227
    'jsx-a11y/img-redundant-alt': 'warn',
228
    'jsx-a11y/no-access-key': 'warn',
229
230
231
232
233
    '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',
234

235
236
    // https://github.com/gajus/eslint-plugin-flowtype
    'flowtype/define-flow-type': 'warn',
237
    'flowtype/require-valid-file-annotation': 'warn',
238
239
    'flowtype/use-flow-type': 'warn',
  },
240
};