UNPKG

8.65 kBJavaScriptView Raw
1"use strict";
2
3module.exports = {
4 plugins: ["react", "react-native"],
5 parserOptions: {
6 ecmaFeatures: {
7 jsx: true,
8 experimentalObjectRestSpread: true,
9 },
10 settings: {
11 react: {
12 createClass: "createClass", // Regex for Component Factory to use, default to "createClass"
13 pragma: "React", // Pragma to use, default to "React"
14 version: "15.0", // React version, default to the latest React stable release
15 },
16 },
17 },
18 rules: {
19 // Constructors of derived classes must call super(). Constructors of non derived classes must not call super()
20 "constructor-super": 2,
21
22 // disallow use of variables before they are defined
23 "no-unused-vars": [
24 2,
25 { argsIgnorePattern: "props|store|next|action|getState|state|^_" },
26 ],
27
28 // disallow extra parentheses
29 "no-extra-parens": 0,
30
31 // disallow use of variables before they are defined
32 "no-use-before-define": 0,
33
34 // Prevent missing displayName in a React component definition
35 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/display-name.md
36 "react/display-name": [1, { ignoreTranspilerName: false }],
37
38 // Forbid certain propTypes (any, array, object)
39 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
40 "react/forbid-prop-types": [1, { forbid: ["any"] }],
41
42 // Enforce boolean attributes notation in JSX
43 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
44 "react/jsx-boolean-value": [2, "always"],
45
46 // Validate closing bracket location in JSX
47 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
48 "react/jsx-closing-bracket-location": [2, "tag-aligned"],
49
50 // Enforce or disallow spaces inside of curly braces in JSX attributes
51 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
52 "react/jsx-curly-spacing": [1, "never", { allowMultiline: true }],
53
54 // Enforce event handler naming conventions in JSX
55 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
56 "react/jsx-handler-names": [0, {}],
57
58 // Validate props indentation in JSX
59 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
60 "react/jsx-indent-props": [2, "tab"],
61
62 // Validate JSX has key prop when in array or iterator
63 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
64 "react/jsx-key": 2,
65
66 // Limit maximum of props on a single line in JSX
67 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
68 "react/jsx-max-props-per-line": [1, { maximum: 3 }],
69
70 // Prevent usage of .bind() and arrow functions in JSX props
71 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
72 "react/jsx-no-bind": [
73 1,
74 {
75 allowArrowFunctions: true,
76 ignoreRefs: true,
77 allowBind: false,
78 },
79 ],
80
81 // Prevent duplicate props in JSX
82 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
83 "react/jsx-no-duplicate-props": [2, { ignoreCase: false }],
84
85 // Prevent usage of unwrapped JSX strings
86 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
87 "react/jsx-no-literals": 0,
88
89 // Disallow undeclared variables in JSX
90 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
91 "react/jsx-no-undef": 2,
92
93 // Enforce PascalCase for user-defined JSX components
94 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
95 "react/jsx-pascal-case": 1,
96
97 // Enforce propTypes declarations alphabetical sorting
98 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-prop-types.md
99 "react/jsx-sort-prop-types": [
100 0,
101 {
102 ignoreCase: false,
103 callbacksLast: false,
104 },
105 ],
106
107 // Enforce props alphabetical sorting
108 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
109 "react/jsx-sort-props": [
110 0,
111 {
112 ignoreCase: false,
113 callbacksLast: false,
114 },
115 ],
116
117 // Prevent React to be incorrectly marked as unused
118 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
119 "react/jsx-uses-react": 2,
120
121 // Prevent variables used in JSX to be incorrectly marked as unused
122 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
123 "react/jsx-uses-vars": 2,
124
125 // Prevent usage of dangerous JSX properties
126 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md
127 "react/no-danger": 1,
128
129 // Prevent usage of deprecated methods
130 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
131 "react/no-deprecated": 1,
132
133 // Prevent usage of setState in componentDidMount
134 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
135 "react/no-did-mount-set-state": [2],
136
137 // Prevent usage of setState in componentDidUpdate
138 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
139 "react/no-did-update-set-state": [2, "disallow-in-func"],
140
141 // Prevent direct mutation of this.state
142 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
143 "react/no-direct-mutation-state": 0,
144
145 // Prevent usage of isMounted
146 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
147 "react/no-is-mounted": 2,
148
149 // Prevent multiple component definition per file
150 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
151 "react/no-multi-comp": 0,
152
153 // Prevent usage of setState
154 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
155 "react/no-set-state": 0,
156
157 // Prevent using string references
158 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
159 "react/no-string-refs": 1,
160
161 // Prevent usage of unknown DOM property
162 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
163 "react/no-unknown-property": 2,
164
165 // Require ES6 class declarations over React.createClass
166 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
167 "react/prefer-es6-class": [2, "always"],
168
169 // Prevent missing props validation in a React component definition
170 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md
171 // disabled until flow types are checked
172 "react/prop-types": [0, { ignore: ["style"], customValidators: [] }],
173
174 // Prevent missing React when using JSX
175 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
176 "react/react-in-jsx-scope": 2,
177
178 // Prevent extra closing tags for components without children
179 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
180 "react/self-closing-comp": 2,
181
182 // Enforce component methods order
183 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
184 "react/sort-comp": [
185 1,
186 {
187 order: [
188 "propTypes",
189 "props",
190 "state",
191 "lifecycle",
192 "/^on.+$/",
193 "/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/",
194 "everything-else",
195 "/^render.+$/",
196 "render",
197 ],
198 },
199 ],
200
201 // Prevent missing parentheses around multilines JSX
202 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
203 "react/jsx-wrap-multilines": [
204 2,
205 {
206 declaration: true,
207 assignment: true,
208 return: true,
209 },
210 ],
211
212 // Ensure correct position of the first property
213 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
214 "react/jsx-first-prop-new-line": [2, "multiline"],
215
216 // Enforce stateless React Components to be written as a pure function
217 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
218 "react/prefer-stateless-function": 1,
219
220 // Enforce ES5 or ES6 class for returning value in render function
221 // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
222 "react/require-render-return": 2,
223
224 // Warn against inline styles
225 "react-native/no-inline-styles": 1,
226
227 // Disallow unused style definitions
228 "react-native/no-unused-styles": 2,
229 },
230};