@pplancq/eslint-config 6.1.4 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/rules/react.js CHANGED
@@ -2,8 +2,11 @@ import jestDom from "eslint-plugin-jest-dom";
2
2
  import reactPlugin from "eslint-plugin-react";
3
3
  import reactHooksPlugin from "eslint-plugin-react-hooks";
4
4
  import testingLibraryPlugin from "eslint-plugin-testing-library";
5
+ /* eslint-disable import/extensions */
6
+ import { prefix } from "./utils.js";
7
+ /* eslint-enable import/extensions */
5
8
 
6
- export const reactRules = {
9
+ export const reactRules = ({ import: importNs = "import-x" } = {}) => ({
7
10
  plugins: {
8
11
  react: reactPlugin,
9
12
  "react-hooks": reactHooksPlugin,
@@ -15,629 +18,633 @@ export const reactRules = {
15
18
  },
16
19
  },
17
20
  },
18
- rules: {
19
- // eslint-plugin-import https://github.com/import-js/eslint-plugin-import
20
-
21
- // import/extensions
22
- // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md
23
- "import/extensions": [
24
- "error",
25
- "ignorePackages",
26
- {
27
- js: "never",
28
- jsx: "never",
29
- },
30
- ],
21
+ rules: prefix(
22
+ {
23
+ // eslint-plugin-import-x https://github.com/un-ts/eslint-plugin-import-x
24
+
25
+ // import-x/extensions
26
+ // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/extensions.md
27
+ "import-x/extensions": [
28
+ "error",
29
+ "ignorePackages",
30
+ {
31
+ js: "never",
32
+ jsx: "never",
33
+ },
34
+ ],
31
35
 
32
- // eslint-plugin-react https://github.com/jsx-eslint/eslint-plugin-react
36
+ // eslint-plugin-react https://github.com/jsx-eslint/eslint-plugin-react
33
37
 
34
- // Enforces consistent naming for boolean props
35
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/boolean-prop-naming.md
36
- "react/boolean-prop-naming": [
37
- "off",
38
- {
39
- propTypeNames: ["bool", "mutuallyExclusiveTrueProps"],
40
- rule: "^(is|has)[A-Z]([A-Za-z0-9]?)+",
41
- message: "",
42
- },
43
- ],
38
+ // Enforces consistent naming for boolean props
39
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/boolean-prop-naming.md
40
+ "react/boolean-prop-naming": [
41
+ "off",
42
+ {
43
+ propTypeNames: ["bool", "mutuallyExclusiveTrueProps"],
44
+ rule: "^(is|has)[A-Z]([A-Za-z0-9]?)+",
45
+ message: "",
46
+ },
47
+ ],
44
48
 
45
- // Disallow usage of `button` elements without an explicit `type` attribute
46
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/button-has-type.md
47
- "react/button-has-type": [
48
- "error",
49
- {
50
- button: true,
51
- submit: true,
52
- reset: false,
53
- },
54
- ],
49
+ // Disallow usage of `button` elements without an explicit `type` attribute
50
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/button-has-type.md
51
+ "react/button-has-type": [
52
+ "error",
53
+ {
54
+ button: true,
55
+ submit: true,
56
+ reset: false,
57
+ },
58
+ ],
55
59
 
56
- // Enforce using `onChange` or `readonly` attribute when `checked` is used
57
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/checked-requires-onchange-or-readonly.md
58
- "react/checked-requires-onchange-or-readonly": "off",
59
-
60
- // Enforce all `defaultProps` have a corresponding non-required `PropType`
61
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/default-props-match-prop-types.md
62
- "react/default-props-match-prop-types": ["error", { allowRequiredDefaults: false }],
63
-
64
- // Enforce consistent usage of destructuring assignment of props, state, and context
65
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md
66
- "react/destructuring-assignment": ["error", "always"],
67
-
68
- // Disallow missing `displayName` in a React component definition
69
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/display-name.md
70
- "react/display-name": "error",
71
-
72
- // Disallow certain props on components
73
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md
74
- "react/forbid-component-props": ["off", { forbid: [] }],
75
-
76
- // Disallow certain props on DOM Nodes
77
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-dom-props.md
78
- "react/forbid-dom-props": ["off", { forbid: [] }],
79
-
80
- // Disallow certain elements
81
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-elements.md
82
- "react/forbid-elements": ["off", { forbid: [] }],
83
-
84
- // Disallow using another component's `propTypes`
85
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md
86
- "react/forbid-foreign-prop-types": ["warn", { allowInPropTypes: true }],
87
-
88
- // Disallow certain `propTypes`
89
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
90
- "react/forbid-prop-types": [
91
- "error",
92
- {
93
- forbid: ["any", "array", "object"],
94
- checkContextTypes: true,
95
- checkChildContextTypes: true,
96
- },
97
- ],
60
+ // Enforce using `onChange` or `readonly` attribute when `checked` is used
61
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/checked-requires-onchange-or-readonly.md
62
+ "react/checked-requires-onchange-or-readonly": "off",
98
63
 
99
- // Enforce a specific `function` type for function components
100
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
101
- "react/function-component-definition": [
102
- "error",
103
- {
104
- namedComponents: ["function-declaration", "arrow-function", "function-expression"],
105
- unnamedComponents: ["arrow-function", "function-expression"],
106
- },
107
- ],
64
+ // Enforce all `defaultProps` have a corresponding non-required `PropType`
65
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/default-props-match-prop-types.md
66
+ "react/default-props-match-prop-types": ["error", { allowRequiredDefaults: false }],
108
67
 
109
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md
110
- "react/hook-use-state": "off",
68
+ // Enforce consistent usage of destructuring assignment of props, state, and context
69
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md
70
+ "react/destructuring-assignment": ["error", "always"],
111
71
 
112
- // Enforce sandbox attribute on `iframe` elements
113
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/iframe-missing-sandbox.md
114
- "react/iframe-missing-sandbox": "off",
72
+ // Disallow missing `displayName` in a React component definition
73
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/display-name.md
74
+ "react/display-name": "error",
115
75
 
116
- // Enforce boolean attributes notation in JSX
117
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
118
- "react/jsx-boolean-value": ["error", "never", { always: [] }],
76
+ // Disallow certain props on components
77
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md
78
+ "react/forbid-component-props": ["off", { forbid: [] }],
119
79
 
120
- // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
121
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-child-element-spacing.md
122
- "react/jsx-child-element-spacing": "off",
80
+ // Disallow certain props on DOM Nodes
81
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-dom-props.md
82
+ "react/forbid-dom-props": ["off", { forbid: [] }],
123
83
 
124
- // Enforce closing bracket location in JSX
125
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
126
- "react/jsx-closing-bracket-location": ["error", "line-aligned"],
84
+ // Disallow certain elements
85
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-elements.md
86
+ "react/forbid-elements": ["off", { forbid: [] }],
127
87
 
128
- // Enforce closing tag location for multiline JSX
129
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md
130
- "react/jsx-closing-tag-location": "error",
88
+ // Disallow using another component's `propTypes`
89
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-foreign-prop-types.md
90
+ "react/forbid-foreign-prop-types": ["warn", { allowInPropTypes: true }],
131
91
 
132
- // Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes
133
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
134
- "react/jsx-curly-brace-presence": ["error", { props: "never", children: "never" }],
92
+ // Disallow certain `propTypes`
93
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-prop-types.md
94
+ "react/forbid-prop-types": [
95
+ "error",
96
+ {
97
+ forbid: ["any", "array", "object"],
98
+ checkContextTypes: true,
99
+ checkChildContextTypes: true,
100
+ },
101
+ ],
135
102
 
136
- // Enforce consistent linebreaks in curly braces in JSX attributes and expressions
137
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-newline.md
138
- "react/jsx-curly-newline": [
139
- "error",
140
- {
141
- multiline: "consistent",
142
- singleline: "consistent",
143
- },
144
- ],
103
+ // Enforce a specific `function` type for function components
104
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
105
+ "react/function-component-definition": [
106
+ "error",
107
+ {
108
+ namedComponents: ["function-declaration", "arrow-function", "function-expression"],
109
+ unnamedComponents: ["arrow-function", "function-expression"],
110
+ },
111
+ ],
145
112
 
146
- // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
147
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
148
- "react/jsx-curly-spacing": ["error", "never", { allowMultiline: true }],
113
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md
114
+ "react/hook-use-state": "off",
149
115
 
150
- // Enforce or disallow spaces around equal signs in JSX attributes
151
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
152
- "react/jsx-equals-spacing": ["error", "never"],
116
+ // Enforce sandbox attribute on `iframe` elements
117
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/iframe-missing-sandbox.md
118
+ "react/iframe-missing-sandbox": "off",
153
119
 
154
- // Disallow file extensions that may contain JSX
155
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
156
- "react/jsx-filename-extension": [
157
- "error",
158
- {
159
- extensions: [".jsx"],
160
- },
161
- ],
120
+ // Enforce boolean attributes notation in JSX
121
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
122
+ "react/jsx-boolean-value": ["error", "never", { always: [] }],
162
123
 
163
- // Enforce proper position of the first property in JSX
164
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
165
- "react/jsx-first-prop-new-line": ["error", "multiline-multiprop"],
166
-
167
- // Enforce shorthand or standard form for React fragments
168
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md
169
- "react/jsx-fragments": ["error", "syntax"],
170
-
171
- // Enforce event handler naming conventions in JSX
172
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
173
- "react/jsx-handler-names": [
174
- "off",
175
- {
176
- eventHandlerPrefix: "handle",
177
- eventHandlerPropPrefix: "on",
178
- },
179
- ],
124
+ // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
125
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-child-element-spacing.md
126
+ "react/jsx-child-element-spacing": "off",
180
127
 
181
- // Enforce JSX indentation
182
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
183
- "react/jsx-indent": ["error", 2],
184
-
185
- // Enforce props indentation in JSX
186
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
187
- "react/jsx-indent-props": ["error", 2],
188
-
189
- // Disallow missing key props in iterators/collection literals
190
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
191
- "react/jsx-key": "error",
192
-
193
- // Enforce JSX maximum depth
194
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-depth.md
195
- "react/jsx-max-depth": "off",
196
-
197
- // Enforce maximum of props on a single line in JSX
198
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
199
- "react/jsx-max-props-per-line": ["error", { maximum: 1, when: "multiline" }],
200
-
201
- // Require or prevent a new line after jsx elements and expressions
202
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-newline.md
203
- "react/jsx-newline": "off",
204
-
205
- // Disallow `.bind()` or arrow functions in JSX props
206
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
207
- "react/jsx-no-bind": [
208
- "error",
209
- {
210
- ignoreRefs: true,
211
- allowArrowFunctions: true,
212
- allowFunctions: false,
213
- allowBind: false,
214
- ignoreDOMComponents: true,
215
- },
216
- ],
128
+ // Enforce closing bracket location in JSX
129
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
130
+ "react/jsx-closing-bracket-location": ["error", "line-aligned"],
217
131
 
218
- // Disallow comments from being inserted as text nodes
219
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
220
- "react/jsx-no-comment-textnodes": "error",
132
+ // Enforce closing tag location for multiline JSX
133
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md
134
+ "react/jsx-closing-tag-location": "error",
221
135
 
222
- // Disallows JSX context provider values from taking values that will cause needless rerenders
223
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-constructed-context-values.md
224
- "react/jsx-no-constructed-context-values": "error",
136
+ // Disallow unnecessary JSX expressions when literals alone are sufficient or enforce JSX expressions on literals in JSX children or attributes
137
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
138
+ "react/jsx-curly-brace-presence": ["error", { props: "never", children: "never" }],
225
139
 
226
- // Disallow duplicate properties in JSX
227
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
228
- "react/jsx-no-duplicate-props": ["error", { ignoreCase: true }],
140
+ // Enforce consistent linebreaks in curly braces in JSX attributes and expressions
141
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-newline.md
142
+ "react/jsx-curly-newline": [
143
+ "error",
144
+ {
145
+ multiline: "consistent",
146
+ singleline: "consistent",
147
+ },
148
+ ],
229
149
 
230
- // Disallow problematic leaked values from being rendered
231
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-leaked-render.md
232
- "react/jsx-no-leaked-render": ["error", { validStrategies: ["ternary", "coerce"] }],
150
+ // Enforce or disallow spaces inside of curly braces in JSX attributes and expressions
151
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
152
+ "react/jsx-curly-spacing": ["error", "never", { allowMultiline: true }],
233
153
 
234
- // Disallow usage of string literals in JSX
235
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
236
- "react/jsx-no-literals": ["off", { noStrings: true }],
154
+ // Enforce or disallow spaces around equal signs in JSX attributes
155
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
156
+ "react/jsx-equals-spacing": ["error", "never"],
237
157
 
238
- // Disallow usage of javascript: `URLs
239
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md
240
- "react/jsx-no-script-url": [
241
- "error",
242
- [
158
+ // Disallow file extensions that may contain JSX
159
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
160
+ "react/jsx-filename-extension": [
161
+ "error",
243
162
  {
244
- name: "Link",
245
- props: ["to"],
163
+ extensions: [".jsx"],
246
164
  },
247
165
  ],
248
- ],
249
166
 
250
- // Disallow `target="_blank"` attribute without `rel="noreferrer"
251
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
252
- "react/jsx-no-target-blank": ["error", { enforceDynamicLinks: "always" }],
253
-
254
- // Disallow undeclared variables in JSX
255
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
256
- "react/jsx-no-undef": "error",
257
-
258
- // Disallow unnecessary fragments
259
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
260
- "react/jsx-no-useless-fragment": "error",
261
-
262
- // Require one JSX element per line
263
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-one-expression-per-line.md
264
- "react/jsx-one-expression-per-line": ["error", { allow: "single-child" }],
265
-
266
- // Enforce PascalCase for user-defined JSX components
267
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
268
- "react/jsx-pascal-case": [
269
- "error",
270
- {
271
- allowAllCaps: true,
272
- ignore: [],
273
- },
274
- ],
167
+ // Enforce proper position of the first property in JSX
168
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
169
+ "react/jsx-first-prop-new-line": ["error", "multiline-multiprop"],
275
170
 
276
- // Disallow multiple spaces between inline JSX props
277
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-multi-spaces.md
278
- "react/jsx-props-no-multi-spaces": "error",
279
-
280
- // Disallow JSX prop spreading the same identifier multiple times
281
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spread-multi.md
282
- "react/jsx-props-no-spread-multi": "off",
283
-
284
- // Disallow JSX prop spreading
285
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
286
- "react/jsx-props-no-spreading": "off",
287
-
288
- // Enforce defaultProps declarations alphabetical sorting
289
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-default-props.md
290
- // This rule is deprecated. It was replaced by react/sort-default-props
291
- "react/jsx-sort-default-props": [
292
- "off",
293
- {
294
- ignoreCase: true,
295
- },
296
- ],
171
+ // Enforce shorthand or standard form for React fragments
172
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md
173
+ "react/jsx-fragments": ["error", "syntax"],
297
174
 
298
- // Enforce props alphabetical sorting
299
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
300
- "react/jsx-sort-props": [
301
- "off",
302
- {
303
- ignoreCase: true,
304
- callbacksLast: false,
305
- shorthandFirst: false,
306
- shorthandLast: false,
307
- noSortAlphabetically: false,
308
- reservedFirst: true,
309
- },
310
- ],
175
+ // Enforce event handler naming conventions in JSX
176
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-handler-names.md
177
+ "react/jsx-handler-names": [
178
+ "off",
179
+ {
180
+ eventHandlerPrefix: "handle",
181
+ eventHandlerPropPrefix: "on",
182
+ },
183
+ ],
311
184
 
312
- // Enforce spacing before closing bracket in JSX
313
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
314
- // This rule is deprecated. It was replaced by react/jsx-tag-spacing
315
- "react/jsx-space-before-closing": ["off", "always"],
316
-
317
- // Enforce whitespace in and around the JSX opening and closing brackets
318
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md
319
- "react/jsx-tag-spacing": [
320
- "error",
321
- {
322
- closingSlash: "never",
323
- beforeSelfClosing: "always",
324
- afterOpening: "never",
325
- beforeClosing: "never",
326
- },
327
- ],
185
+ // Enforce JSX indentation
186
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
187
+ "react/jsx-indent": ["error", 2],
328
188
 
329
- // Disallow `React` to be incorrectly marked as unused
330
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
331
- "react/jsx-uses-react": "off",
332
-
333
- // Disallow variables used in JSX to be incorrectly marked as unused
334
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
335
- "react/jsx-uses-vars": "error",
336
-
337
- // Disallow missing parentheses around multiline JSX
338
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
339
- "react/jsx-wrap-multilines": [
340
- "error",
341
- {
342
- declaration: "parens-new-line",
343
- assignment: "parens-new-line",
344
- return: "parens-new-line",
345
- arrow: "parens-new-line",
346
- condition: "parens-new-line",
347
- logical: "parens-new-line",
348
- prop: "parens-new-line",
349
- },
350
- ],
189
+ // Enforce props indentation in JSX
190
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
191
+ "react/jsx-indent-props": ["error", 2],
351
192
 
352
- // Disallow when `this.state` is accessed within `setState`
353
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
354
- "react/no-access-state-in-setstate": "error",
193
+ // Disallow missing key props in iterators/collection literals
194
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
195
+ "react/jsx-key": "error",
355
196
 
356
- // Disallow adjacent inline elements not separated by whitespace
357
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-adjacent-inline-elements.md
358
- "react/no-adjacent-inline-elements": "off",
197
+ // Enforce JSX maximum depth
198
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-depth.md
199
+ "react/jsx-max-depth": "off",
359
200
 
360
- // Disallow usage of `Array` index in keys
361
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
362
- "react/no-array-index-key": "error",
201
+ // Enforce maximum of props on a single line in JSX
202
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
203
+ "react/jsx-max-props-per-line": ["error", { maximum: 1, when: "multiline" }],
363
204
 
364
- // Lifecycle methods should be methods on the prototype, not class fields
365
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-arrow-function-lifecycle.md
366
- "react/no-arrow-function-lifecycle": "error",
205
+ // Require or prevent a new line after jsx elements and expressions
206
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-newline.md
207
+ "react/jsx-newline": "off",
367
208
 
368
- // Disallow passing of children as props
369
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
370
- "react/no-children-prop": "error",
209
+ // Disallow `.bind()` or arrow functions in JSX props
210
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
211
+ "react/jsx-no-bind": [
212
+ "error",
213
+ {
214
+ ignoreRefs: true,
215
+ allowArrowFunctions: true,
216
+ allowFunctions: false,
217
+ allowBind: false,
218
+ ignoreDOMComponents: true,
219
+ },
220
+ ],
371
221
 
372
- // Disallow usage of dangerous JSX properties
373
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger.md
374
- "react/no-danger": "warn",
222
+ // Disallow comments from being inserted as text nodes
223
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
224
+ "react/jsx-no-comment-textnodes": "error",
225
+
226
+ // Disallows JSX context provider values from taking values that will cause needless rerenders
227
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-constructed-context-values.md
228
+ "react/jsx-no-constructed-context-values": "error",
229
+
230
+ // Disallow duplicate properties in JSX
231
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
232
+ "react/jsx-no-duplicate-props": ["error", { ignoreCase: true }],
233
+
234
+ // Disallow problematic leaked values from being rendered
235
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-leaked-render.md
236
+ "react/jsx-no-leaked-render": ["error", { validStrategies: ["ternary", "coerce"] }],
237
+
238
+ // Disallow usage of string literals in JSX
239
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
240
+ "react/jsx-no-literals": ["off", { noStrings: true }],
241
+
242
+ // Disallow usage of javascript: `URLs
243
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-script-url.md
244
+ "react/jsx-no-script-url": [
245
+ "error",
246
+ [
247
+ {
248
+ name: "Link",
249
+ props: ["to"],
250
+ },
251
+ ],
252
+ ],
375
253
 
376
- // Disallow when a DOM element is using both `children` and `dangerouslySetInnerHTML`
377
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
378
- "react/no-danger-with-children": "error",
254
+ // Disallow `target="_blank"` attribute without `rel="noreferrer"
255
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
256
+ "react/jsx-no-target-blank": ["error", { enforceDynamicLinks: "always" }],
379
257
 
380
- // Disallow usage of deprecated methods
381
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
382
- "react/no-deprecated": "error",
258
+ // Disallow undeclared variables in JSX
259
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
260
+ "react/jsx-no-undef": "error",
383
261
 
384
- // Disallow usage of `setState` in `componentDidMount`
385
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
386
- "react/no-did-mount-set-state": "off",
262
+ // Disallow unnecessary fragments
263
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
264
+ "react/jsx-no-useless-fragment": "error",
387
265
 
388
- // Disallow usage of `setState` in `componentDidUpdate`
389
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
390
- "react/no-did-update-set-state": "error",
266
+ // Require one JSX element per line
267
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-one-expression-per-line.md
268
+ "react/jsx-one-expression-per-line": ["error", { allow: "single-child" }],
391
269
 
392
- // Disallow direct mutation of `this.state`
393
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
394
- "react/no-direct-mutation-state": "error",
270
+ // Enforce PascalCase for user-defined JSX components
271
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
272
+ "react/jsx-pascal-case": [
273
+ "error",
274
+ {
275
+ allowAllCaps: true,
276
+ ignore: [],
277
+ },
278
+ ],
395
279
 
396
- // Disallow usage of `findDOMNode`
397
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md
398
- "react/no-find-dom-node": "error",
280
+ // Disallow multiple spaces between inline JSX props
281
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-multi-spaces.md
282
+ "react/jsx-props-no-multi-spaces": "error",
399
283
 
400
- // Disallow usage of invalid attributes
401
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-invalid-html-attribute.md
402
- "react/no-invalid-html-attribute": "error",
284
+ // Disallow JSX prop spreading the same identifier multiple times
285
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spread-multi.md
286
+ "react/jsx-props-no-spread-multi": "off",
403
287
 
404
- // Disallow usage of `isMounted`
405
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
406
- "react/no-is-mounted": "error",
288
+ // Disallow JSX prop spreading
289
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-props-no-spreading.md
290
+ "react/jsx-props-no-spreading": "off",
407
291
 
408
- // Disallow multiple component definition per file
409
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
410
- "react/no-multi-comp": [
411
- "error",
412
- {
413
- ignoreStateless: false,
414
- },
415
- ],
292
+ // Enforce defaultProps declarations alphabetical sorting
293
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-default-props.md
294
+ // This rule is deprecated. It was replaced by react/sort-default-props
295
+ "react/jsx-sort-default-props": [
296
+ "off",
297
+ {
298
+ ignoreCase: true,
299
+ },
300
+ ],
416
301
 
417
- // Enforce that namespaces are not used in React elements
418
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-namespace.md
419
- "react/no-namespace": "error",
420
-
421
- // Disallow usage of referential-type variables as default param in functional component
422
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-object-type-as-default-prop.md
423
- "react/no-object-type-as-default-prop": "off",
424
-
425
- // Disallow usage of `shouldComponentUpdate` when extending `React.PureComponent`
426
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-redundant-should-component-update.md
427
- "react/no-redundant-should-component-update": "error",
428
-
429
- // Disallow usage of the return value of `ReactDOM.render`
430
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
431
- "react/no-render-return-value": "error",
432
-
433
- // Disallow usage of `setState`
434
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
435
- "react/no-set-state": "off",
436
-
437
- // Disallow using string references
438
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
439
- "react/no-string-refs": "error",
440
-
441
- // Disallow `this` from being used in stateless functional components
442
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-this-in-sfc.md
443
- "react/no-this-in-sfc": "error",
444
-
445
- // Disallow common typos
446
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-typos.md
447
- "react/no-typos": "error",
448
-
449
- // Disallow unescaped HTML entities from appearing in markup
450
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
451
- "react/no-unescaped-entities": "off",
452
-
453
- // Disallow usage of unknown DOM property
454
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
455
- "react/no-unknown-property": "error",
456
-
457
- // Disallow usage of unsafe lifecycle methods
458
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unsafe.md
459
- "react/no-unsafe": "off",
460
-
461
- // Disallow creating unstable components inside components
462
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unstable-nested-components.md
463
- "react/no-unstable-nested-components": "error",
464
-
465
- // Disallow declaring unused methods of component class
466
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-class-component-methods.md
467
- "react/no-unused-class-component-methods": "error",
468
-
469
- // Disallow definitions of unused `propTypes`
470
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
471
- "react/no-unused-prop-types": [
472
- "error",
473
- {
474
- customValidators: [],
475
- skipShapeProps: true,
476
- },
477
- ],
302
+ // Enforce props alphabetical sorting
303
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
304
+ "react/jsx-sort-props": [
305
+ "off",
306
+ {
307
+ ignoreCase: true,
308
+ callbacksLast: false,
309
+ shorthandFirst: false,
310
+ shorthandLast: false,
311
+ noSortAlphabetically: false,
312
+ reservedFirst: true,
313
+ },
314
+ ],
478
315
 
479
- // Disallow definitions of unused state
480
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-state.md
481
- "react/no-unused-state": "error",
482
-
483
- // Disallow usage of `setState` in `componentWillUpdate`
484
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-will-update-set-state.md
485
- "react/no-will-update-set-state": "error",
486
-
487
- // Enforce ES5 or ES6 class for React Components
488
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
489
- "react/prefer-es6-class": ["error", "always"],
490
-
491
- // Prefer exact `proptype` definitions
492
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-exact-props.md
493
- "react/prefer-exact-props": "error",
494
-
495
- // Enforce that props are read-only
496
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-read-only-props.md
497
- "react/prefer-read-only-props": "off",
498
-
499
- // Enforce stateless components to be written as a pure `function`
500
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
501
- "react/prefer-stateless-function": ["error", { ignorePureComponents: true }],
502
-
503
- // Disallow missing props validation in a React component definition
504
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prop-types.md
505
- "react/prop-types": [
506
- "error",
507
- {
508
- ignore: [],
509
- customValidators: [],
510
- skipUndeclared: false,
511
- },
512
- ],
316
+ // Enforce spacing before closing bracket in JSX
317
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
318
+ // This rule is deprecated. It was replaced by react/jsx-tag-spacing
319
+ "react/jsx-space-before-closing": ["off", "always"],
513
320
 
514
- // Disallow missing `React` when using JSX
515
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
516
- "react/react-in-jsx-scope": "off",
321
+ // Enforce whitespace in and around the JSX opening and closing brackets
322
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md
323
+ "react/jsx-tag-spacing": [
324
+ "error",
325
+ {
326
+ closingSlash: "never",
327
+ beforeSelfClosing: "always",
328
+ afterOpening: "never",
329
+ beforeClosing: "never",
330
+ },
331
+ ],
517
332
 
518
- // Enforce a `defaultProps` definition for every prop that is not a required prop
519
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
520
- "react/require-default-props": [
521
- "error",
522
- {
523
- forbidDefaultForRequired: true,
524
- },
525
- ],
333
+ // Disallow `React` to be incorrectly marked as unused
334
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-react.md
335
+ "react/jsx-uses-react": "off",
526
336
 
527
- // Enforce React components to have a `shouldComponentUpdate` method
528
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-optimization.md
529
- "react/require-optimization": ["off", { allowDecorators: [] }],
530
-
531
- // Enforce ES5 or ES6 class for returning value in `render` function
532
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
533
- "react/require-render-return": "error",
534
-
535
- // Disallow extra closing tags for components without children
536
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
537
- "react/self-closing-comp": "error",
538
-
539
- // Enforce component methods order
540
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
541
- "react/sort-comp": [
542
- "error",
543
- {
544
- order: [
545
- "static-variables",
546
- "static-methods",
547
- "instance-variables",
548
- "lifecycle",
549
- "/^handle.+$/",
550
- "/^on.+$/",
551
- "getters",
552
- "setters",
553
- "/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/",
554
- "instance-methods",
555
- "everything-else",
556
- "rendering",
557
- ],
558
- groups: {
559
- lifecycle: [
560
- "displayName",
561
- "propTypes",
562
- "contextTypes",
563
- "childContextTypes",
564
- "mixins",
565
- "statics",
566
- "defaultProps",
567
- "constructor",
568
- "getDefaultProps",
569
- "getInitialState",
570
- "state",
571
- "getChildContext",
572
- "getDerivedStateFromProps",
573
- "componentWillMount",
574
- "UNSAFE_componentWillMount",
575
- "componentDidMount",
576
- "componentWillReceiveProps",
577
- "UNSAFE_componentWillReceiveProps",
578
- "shouldComponentUpdate",
579
- "componentWillUpdate",
580
- "UNSAFE_componentWillUpdate",
581
- "getSnapshotBeforeUpdate",
582
- "componentDidUpdate",
583
- "componentDidCatch",
584
- "componentWillUnmount",
337
+ // Disallow variables used in JSX to be incorrectly marked as unused
338
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
339
+ "react/jsx-uses-vars": "error",
340
+
341
+ // Disallow missing parentheses around multiline JSX
342
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-wrap-multilines.md
343
+ "react/jsx-wrap-multilines": [
344
+ "error",
345
+ {
346
+ declaration: "parens-new-line",
347
+ assignment: "parens-new-line",
348
+ return: "parens-new-line",
349
+ arrow: "parens-new-line",
350
+ condition: "parens-new-line",
351
+ logical: "parens-new-line",
352
+ prop: "parens-new-line",
353
+ },
354
+ ],
355
+
356
+ // Disallow when `this.state` is accessed within `setState`
357
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
358
+ "react/no-access-state-in-setstate": "error",
359
+
360
+ // Disallow adjacent inline elements not separated by whitespace
361
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-adjacent-inline-elements.md
362
+ "react/no-adjacent-inline-elements": "off",
363
+
364
+ // Disallow usage of `Array` index in keys
365
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
366
+ "react/no-array-index-key": "error",
367
+
368
+ // Lifecycle methods should be methods on the prototype, not class fields
369
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-arrow-function-lifecycle.md
370
+ "react/no-arrow-function-lifecycle": "error",
371
+
372
+ // Disallow passing of children as props
373
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
374
+ "react/no-children-prop": "error",
375
+
376
+ // Disallow usage of dangerous JSX properties
377
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger.md
378
+ "react/no-danger": "warn",
379
+
380
+ // Disallow when a DOM element is using both `children` and `dangerouslySetInnerHTML`
381
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
382
+ "react/no-danger-with-children": "error",
383
+
384
+ // Disallow usage of deprecated methods
385
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
386
+ "react/no-deprecated": "error",
387
+
388
+ // Disallow usage of `setState` in `componentDidMount`
389
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md
390
+ "react/no-did-mount-set-state": "off",
391
+
392
+ // Disallow usage of `setState` in `componentDidUpdate`
393
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-did-update-set-state.md
394
+ "react/no-did-update-set-state": "error",
395
+
396
+ // Disallow direct mutation of `this.state`
397
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
398
+ "react/no-direct-mutation-state": "error",
399
+
400
+ // Disallow usage of `findDOMNode`
401
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-find-dom-node.md
402
+ "react/no-find-dom-node": "error",
403
+
404
+ // Disallow usage of invalid attributes
405
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-invalid-html-attribute.md
406
+ "react/no-invalid-html-attribute": "error",
407
+
408
+ // Disallow usage of `isMounted`
409
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-is-mounted.md
410
+ "react/no-is-mounted": "error",
411
+
412
+ // Disallow multiple component definition per file
413
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
414
+ "react/no-multi-comp": [
415
+ "error",
416
+ {
417
+ ignoreStateless: false,
418
+ },
419
+ ],
420
+
421
+ // Enforce that namespaces are not used in React elements
422
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-namespace.md
423
+ "react/no-namespace": "error",
424
+
425
+ // Disallow usage of referential-type variables as default param in functional component
426
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-object-type-as-default-prop.md
427
+ "react/no-object-type-as-default-prop": "off",
428
+
429
+ // Disallow usage of `shouldComponentUpdate` when extending `React.PureComponent`
430
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-redundant-should-component-update.md
431
+ "react/no-redundant-should-component-update": "error",
432
+
433
+ // Disallow usage of the return value of `ReactDOM.render`
434
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
435
+ "react/no-render-return-value": "error",
436
+
437
+ // Disallow usage of `setState`
438
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-set-state.md
439
+ "react/no-set-state": "off",
440
+
441
+ // Disallow using string references
442
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
443
+ "react/no-string-refs": "error",
444
+
445
+ // Disallow `this` from being used in stateless functional components
446
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-this-in-sfc.md
447
+ "react/no-this-in-sfc": "error",
448
+
449
+ // Disallow common typos
450
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-typos.md
451
+ "react/no-typos": "error",
452
+
453
+ // Disallow unescaped HTML entities from appearing in markup
454
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
455
+ "react/no-unescaped-entities": "off",
456
+
457
+ // Disallow usage of unknown DOM property
458
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
459
+ "react/no-unknown-property": "error",
460
+
461
+ // Disallow usage of unsafe lifecycle methods
462
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unsafe.md
463
+ "react/no-unsafe": "off",
464
+
465
+ // Disallow creating unstable components inside components
466
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unstable-nested-components.md
467
+ "react/no-unstable-nested-components": "error",
468
+
469
+ // Disallow declaring unused methods of component class
470
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-class-component-methods.md
471
+ "react/no-unused-class-component-methods": "error",
472
+
473
+ // Disallow definitions of unused `propTypes`
474
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
475
+ "react/no-unused-prop-types": [
476
+ "error",
477
+ {
478
+ customValidators: [],
479
+ skipShapeProps: true,
480
+ },
481
+ ],
482
+
483
+ // Disallow definitions of unused state
484
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-state.md
485
+ "react/no-unused-state": "error",
486
+
487
+ // Disallow usage of `setState` in `componentWillUpdate`
488
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-will-update-set-state.md
489
+ "react/no-will-update-set-state": "error",
490
+
491
+ // Enforce ES5 or ES6 class for React Components
492
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-es6-class.md
493
+ "react/prefer-es6-class": ["error", "always"],
494
+
495
+ // Prefer exact `proptype` definitions
496
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-exact-props.md
497
+ "react/prefer-exact-props": "error",
498
+
499
+ // Enforce that props are read-only
500
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-read-only-props.md
501
+ "react/prefer-read-only-props": "off",
502
+
503
+ // Enforce stateless components to be written as a pure `function`
504
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
505
+ "react/prefer-stateless-function": ["error", { ignorePureComponents: true }],
506
+
507
+ // Disallow missing props validation in a React component definition
508
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prop-types.md
509
+ "react/prop-types": [
510
+ "error",
511
+ {
512
+ ignore: [],
513
+ customValidators: [],
514
+ skipUndeclared: false,
515
+ },
516
+ ],
517
+
518
+ // Disallow missing `React` when using JSX
519
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md
520
+ "react/react-in-jsx-scope": "off",
521
+
522
+ // Enforce a `defaultProps` definition for every prop that is not a required prop
523
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
524
+ "react/require-default-props": [
525
+ "error",
526
+ {
527
+ forbidDefaultForRequired: true,
528
+ },
529
+ ],
530
+
531
+ // Enforce React components to have a `shouldComponentUpdate` method
532
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-optimization.md
533
+ "react/require-optimization": ["off", { allowDecorators: [] }],
534
+
535
+ // Enforce ES5 or ES6 class for returning value in `render` function
536
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-render-return.md
537
+ "react/require-render-return": "error",
538
+
539
+ // Disallow extra closing tags for components without children
540
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
541
+ "react/self-closing-comp": "error",
542
+
543
+ // Enforce component methods order
544
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-comp.md
545
+ "react/sort-comp": [
546
+ "error",
547
+ {
548
+ order: [
549
+ "static-variables",
550
+ "static-methods",
551
+ "instance-variables",
552
+ "lifecycle",
553
+ "/^handle.+$/",
554
+ "/^on.+$/",
555
+ "getters",
556
+ "setters",
557
+ "/^(get|set)(?!(InitialState$|DefaultProps$|ChildContext$)).+$/",
558
+ "instance-methods",
559
+ "everything-else",
560
+ "rendering",
585
561
  ],
586
- rendering: ["/^render.+$/", "render"],
562
+ groups: {
563
+ lifecycle: [
564
+ "displayName",
565
+ "propTypes",
566
+ "contextTypes",
567
+ "childContextTypes",
568
+ "mixins",
569
+ "statics",
570
+ "defaultProps",
571
+ "constructor",
572
+ "getDefaultProps",
573
+ "getInitialState",
574
+ "state",
575
+ "getChildContext",
576
+ "getDerivedStateFromProps",
577
+ "componentWillMount",
578
+ "UNSAFE_componentWillMount",
579
+ "componentDidMount",
580
+ "componentWillReceiveProps",
581
+ "UNSAFE_componentWillReceiveProps",
582
+ "shouldComponentUpdate",
583
+ "componentWillUpdate",
584
+ "UNSAFE_componentWillUpdate",
585
+ "getSnapshotBeforeUpdate",
586
+ "componentDidUpdate",
587
+ "componentDidCatch",
588
+ "componentWillUnmount",
589
+ ],
590
+ rendering: ["/^render.+$/", "render"],
591
+ },
587
592
  },
588
- },
589
- ],
593
+ ],
590
594
 
591
- // Enforce defaultProps declarations alphabetical sorting
592
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-default-props.md
593
- "react/sort-default-props": "off",
594
-
595
- // Enforce propTypes declarations alphabetical sorting
596
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
597
- "react/sort-prop-types": [
598
- "off",
599
- {
600
- ignoreCase: true,
601
- callbacksLast: false,
602
- requiredFirst: false,
603
- sortShapeProp: true,
604
- },
605
- ],
595
+ // Enforce defaultProps declarations alphabetical sorting
596
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-default-props.md
597
+ "react/sort-default-props": "off",
606
598
 
607
- // Enforce class component state initialization style
608
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/state-in-constructor.md
609
- "react/state-in-constructor": ["error", "always"],
599
+ // Enforce propTypes declarations alphabetical sorting
600
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/sort-prop-types.md
601
+ "react/sort-prop-types": [
602
+ "off",
603
+ {
604
+ ignoreCase: true,
605
+ callbacksLast: false,
606
+ requiredFirst: false,
607
+ sortShapeProp: true,
608
+ },
609
+ ],
610
610
 
611
- // Enforces where React component static properties should be positioned
612
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/static-property-placement.md
613
- "react/static-property-placement": ["error", "property assignment"],
611
+ // Enforce class component state initialization style
612
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/state-in-constructor.md
613
+ "react/state-in-constructor": ["error", "always"],
614
614
 
615
- // Enforce `style` prop value is an object
616
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md
617
- "react/style-prop-object": "error",
615
+ // Enforces where React component static properties should be positioned
616
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/static-property-placement.md
617
+ "react/static-property-placement": ["error", "property assignment"],
618
618
 
619
- // Disallow void DOM elements (e.g. `<img />`, `<br />`) from receiving children
620
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md
621
- "react/void-dom-elements-no-children": "error",
619
+ // Enforce `style` prop value is an object
620
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md
621
+ "react/style-prop-object": "error",
622
622
 
623
- // eslint-plugin-react-hooks https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hook
623
+ // Disallow void DOM elements (e.g. `<img />`, `<br />`) from receiving children
624
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/void-dom-elements-no-children.md
625
+ "react/void-dom-elements-no-children": "error",
624
626
 
625
- // Enforce Rules of Hooks
626
- // https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
627
- // https://react.dev/reference/rules/rules-of-hooks
628
- "react-hooks/rules-of-hooks": "error",
627
+ // eslint-plugin-react-hooks https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hook
629
628
 
630
- // Verify the list of the dependencies for Hooks like `useEffect` and similar
631
- // https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
632
- // https://github.com/facebook/react/issues/14920
633
- "react-hooks/exhaustive-deps": "warn",
634
- },
629
+ // Enforce Rules of Hooks
630
+ // https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
631
+ // https://react.dev/reference/rules/rules-of-hooks
632
+ "react-hooks/rules-of-hooks": "error",
633
+
634
+ // Verify the list of the dependencies for Hooks like `useEffect` and similar
635
+ // https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js
636
+ // https://github.com/facebook/react/issues/14920
637
+ "react-hooks/exhaustive-deps": "warn",
638
+ },
639
+ "import-x",
640
+ importNs,
641
+ ),
635
642
  settings: {
636
643
  react: {
637
644
  pragma: "React",
638
645
  version: "detect",
639
646
  },
640
- "import/resolver": {
647
+ "import-x/resolver": {
641
648
  node: {
642
649
  extensions: [".js", ".jsx"],
643
650
  },
@@ -648,11 +655,11 @@ export const reactRules = {
648
655
  "Object.freeze", // https://tc39.github.io/ecma262/#sec-object.freeze
649
656
  ],
650
657
  },
651
- };
658
+ });
652
659
 
653
- export const reactTypescriptRules = {
660
+ export const reactTypescriptRules = ({ files, import: importNs = "import-x" } = {}) => ({
654
661
  settings: {
655
- "import/resolver": {
662
+ "import-x/resolver": {
656
663
  node: {
657
664
  extensions: [".js", ".jsx", ".ts", ".tsx"],
658
665
  },
@@ -663,40 +670,45 @@ export const reactTypescriptRules = {
663
670
  jsxPragma: null,
664
671
  },
665
672
  },
666
- rules: {
667
- // eslint-plugin-import https://github.com/import-js/eslint-plugin-import
668
-
669
- // import/extensions
670
- // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md
671
- "import/extensions": [
672
- "error",
673
- "ignorePackages",
674
- {
675
- js: "never",
676
- jsx: "never",
677
- ts: "never",
678
- tsx: "never",
679
- },
680
- ],
673
+ rules: prefix(
674
+ {
675
+ // eslint-plugin-import-x https://github.com/un-ts/eslint-plugin-import-x
676
+
677
+ // import-x/extensions
678
+ // https://github.com/un-ts/eslint-plugin-import-x/blob/master/docs/rules/extensions.md
679
+ "import-x/extensions": [
680
+ "error",
681
+ "ignorePackages",
682
+ {
683
+ js: "never",
684
+ jsx: "never",
685
+ ts: "never",
686
+ tsx: "never",
687
+ },
688
+ ],
681
689
 
682
- // eslint-plugin-react https://github.com/jsx-eslint/eslint-plugin-react
690
+ // eslint-plugin-react https://github.com/jsx-eslint/eslint-plugin-react
683
691
 
684
- // Enforce a defaultProps definition for every prop that is not a required prop
685
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
686
- "react/require-default-props": "off",
692
+ // Enforce a defaultProps definition for every prop that is not a required prop
693
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/require-default-props.md
694
+ "react/require-default-props": "off",
687
695
 
688
- // Disallow file extensions that may contain JSX
689
- // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
690
- "react/jsx-filename-extension": [
691
- "error",
692
- {
693
- extensions: [".jsx", ".tsx"],
694
- },
695
- ],
696
- },
697
- };
696
+ // Disallow file extensions that may contain JSX
697
+ // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
698
+ "react/jsx-filename-extension": [
699
+ "error",
700
+ {
701
+ extensions: [".jsx", ".tsx"],
702
+ },
703
+ ],
704
+ },
705
+ "import-x",
706
+ importNs,
707
+ ),
708
+ files,
709
+ });
698
710
 
699
- export const reactTestRules = {
711
+ export const reactTestRules = ({ files } = {}) => ({
700
712
  plugins: {
701
713
  "testing-library": testingLibraryPlugin,
702
714
  "jest-dom": jestDom,
@@ -858,4 +870,5 @@ export const reactTestRules = {
858
870
  // https://github.com/testing-library/eslint-plugin-testing-library/blob/main/docs/rules/render-result-naming-convention.md
859
871
  "testing-library/render-result-naming-convention": "error",
860
872
  },
861
- };
873
+ files,
874
+ });