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

  parserOptions: {
42
    ecmaVersion: 2018,
43
44
45
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
46
    },
47
48
49
50
  },

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

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

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

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

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