UNPKG

7.5 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8'use strict';
9
10// Inspired by https://github.com/airbnb/javascript but less opinionated.
11
12// We use eslint-loader so even warnings are very visible.
13// This is why we only use "WARNING" level for potential errors,
14// and we don't use "ERROR" level at all.
15
16// In the future, we might create a separate list of rules for production.
17// It would probably be more strict.
18
19// The ESLint browser environment defines all browser globals as valid,
20// even though most people don't know some of them exist (e.g. `name` or `status`).
21// This is dangerous as it hides accidentally undefined variables.
22// We blacklist the globals that we deem potentially confusing.
23// To use them, explicitly reference them, e.g. `window.name` or `window.status`.
24var restrictedGlobals = require('confusing-browser-globals');
25
26module.exports = {
27 root: true,
28
29 parser: 'babel-eslint',
30
31 plugins: ['import', 'flowtype', 'jsx-a11y', 'react'],
32
33 env: {
34 browser: true,
35 commonjs: true,
36 es6: true,
37 jest: true,
38 node: true,
39 },
40
41 parserOptions: {
42 ecmaVersion: 2018,
43 sourceType: 'module',
44 ecmaFeatures: {
45 jsx: true,
46 },
47 },
48
49 rules: {
50 // http://eslint.org/docs/rules/
51 'array-callback-return': 'warn',
52 'default-case': ['warn', { commentPattern: '^no default$' }],
53 'dot-location': ['warn', 'property'],
54 eqeqeq: ['warn', 'smart'],
55 'new-parens': 'warn',
56 'no-array-constructor': 'warn',
57 'no-caller': 'warn',
58 'no-cond-assign': ['warn', 'except-parens'],
59 'no-const-assign': 'warn',
60 'no-control-regex': 'warn',
61 'no-delete-var': 'warn',
62 'no-dupe-args': 'warn',
63 'no-dupe-class-members': 'warn',
64 'no-dupe-keys': 'warn',
65 'no-duplicate-case': 'warn',
66 'no-empty-character-class': 'warn',
67 'no-empty-pattern': 'warn',
68 'no-eval': 'warn',
69 'no-ex-assign': 'warn',
70 'no-extend-native': 'warn',
71 'no-extra-bind': 'warn',
72 'no-extra-label': 'warn',
73 'no-fallthrough': 'warn',
74 'no-func-assign': 'warn',
75 'no-implied-eval': 'warn',
76 'no-invalid-regexp': 'warn',
77 'no-iterator': 'warn',
78 'no-label-var': 'warn',
79 'no-labels': ['warn', { allowLoop: true, allowSwitch: false }],
80 'no-lone-blocks': 'warn',
81 'no-loop-func': 'warn',
82 'no-mixed-operators': [
83 'warn',
84 {
85 groups: [
86 ['&', '|', '^', '~', '<<', '>>', '>>>'],
87 ['==', '!=', '===', '!==', '>', '>=', '<', '<='],
88 ['&&', '||'],
89 ['in', 'instanceof'],
90 ],
91 allowSamePrecedence: false,
92 },
93 ],
94 'no-multi-str': 'warn',
95 'no-native-reassign': 'warn',
96 'no-negated-in-lhs': 'warn',
97 'no-new-func': 'warn',
98 'no-new-object': 'warn',
99 'no-new-symbol': 'warn',
100 'no-new-wrappers': 'warn',
101 'no-obj-calls': 'warn',
102 'no-octal': 'warn',
103 'no-octal-escape': 'warn',
104 'no-redeclare': 'warn',
105 'no-regex-spaces': 'warn',
106 'no-restricted-syntax': ['warn', 'WithStatement'],
107 'no-script-url': 'warn',
108 'no-self-assign': 'warn',
109 'no-self-compare': 'warn',
110 'no-sequences': 'warn',
111 'no-shadow-restricted-names': 'warn',
112 'no-sparse-arrays': 'warn',
113 'no-template-curly-in-string': 'warn',
114 'no-this-before-super': 'warn',
115 'no-throw-literal': 'warn',
116 'no-undef': 'error',
117 'no-restricted-globals': ['error'].concat(restrictedGlobals),
118 'no-unexpected-multiline': 'warn',
119 'no-unreachable': 'warn',
120 'no-unused-expressions': [
121 'error',
122 {
123 allowShortCircuit: true,
124 allowTernary: true,
125 allowTaggedTemplates: true,
126 },
127 ],
128 'no-unused-labels': 'warn',
129 'no-unused-vars': [
130 'warn',
131 {
132 args: 'none',
133 ignoreRestSiblings: true,
134 },
135 ],
136 'no-use-before-define': [
137 'warn',
138 {
139 functions: false,
140 classes: false,
141 variables: false,
142 },
143 ],
144 'no-useless-computed-key': 'warn',
145 'no-useless-concat': 'warn',
146 'no-useless-constructor': 'warn',
147 'no-useless-escape': 'warn',
148 'no-useless-rename': [
149 'warn',
150 {
151 ignoreDestructuring: false,
152 ignoreImport: false,
153 ignoreExport: false,
154 },
155 ],
156 'no-with': 'warn',
157 'no-whitespace-before-property': 'warn',
158 'require-yield': 'warn',
159 'rest-spread-spacing': ['warn', 'never'],
160 strict: ['warn', 'never'],
161 'unicode-bom': ['warn', 'never'],
162 'use-isnan': 'warn',
163 'valid-typeof': 'warn',
164 'no-restricted-properties': [
165 'error',
166 {
167 object: 'require',
168 property: 'ensure',
169 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 object: 'System',
174 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
181 // https://github.com/benmosher/eslint-plugin-import/tree/master/docs/rules
182 'import/first': 'error',
183 '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 }],
188 'react/jsx-no-comment-textnodes': 'warn',
189 'react/jsx-no-duplicate-props': ['warn', { ignoreCase: true }],
190 'react/jsx-no-target-blank': 'warn',
191 'react/jsx-no-undef': 'error',
192 'react/jsx-pascal-case': [
193 'warn',
194 {
195 allowAllCaps: true,
196 ignore: [],
197 },
198 ],
199 'react/jsx-uses-react': 'warn',
200 'react/jsx-uses-vars': 'warn',
201 'react/no-danger-with-children': 'warn',
202 // Disabled because of undesirable warnings
203 // See https://github.com/facebook/create-react-app/issues/5204 for
204 // blockers until its re-enabled
205 // 'react/no-deprecated': 'warn',
206 'react/no-direct-mutation-state': 'warn',
207 'react/no-is-mounted': 'warn',
208 'react/react-in-jsx-scope': 'error',
209 'react/require-render-return': 'error',
210 'react/style-prop-object': 'warn',
211
212 // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
213 'jsx-a11y/accessible-emoji': 'warn',
214 'jsx-a11y/alt-text': 'warn',
215 'jsx-a11y/anchor-has-content': 'warn',
216 'jsx-a11y/anchor-is-valid': [
217 'warn',
218 {
219 aspects: ['noHref', 'invalidHref'],
220 },
221 ],
222 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
223 'jsx-a11y/aria-props': 'warn',
224 'jsx-a11y/aria-proptypes': 'warn',
225 'jsx-a11y/aria-role': 'warn',
226 'jsx-a11y/aria-unsupported-elements': 'warn',
227 'jsx-a11y/heading-has-content': 'warn',
228 'jsx-a11y/iframe-has-title': 'warn',
229 'jsx-a11y/img-redundant-alt': 'warn',
230 'jsx-a11y/no-access-key': 'warn',
231 'jsx-a11y/no-distracting-elements': 'warn',
232 'jsx-a11y/no-redundant-roles': 'warn',
233 'jsx-a11y/role-has-required-aria-props': 'warn',
234 'jsx-a11y/role-supports-aria-props': 'warn',
235 'jsx-a11y/scope': 'warn',
236
237 // https://github.com/gajus/eslint-plugin-flowtype
238 'flowtype/define-flow-type': 'warn',
239 'flowtype/require-valid-file-annotation': 'warn',
240 'flowtype/use-flow-type': 'warn',
241 },
242};