@viclafouch/eslint-config-viclafouch 3.9.2 → 3.9.3-beta.1
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/.eslintrc +10 -0
- package/README.md +120 -40
- package/hooks.js +7 -0
- package/index.js +19 -3
- package/next.js +19 -0
- package/package.json +17 -27
- package/prettier.js +23 -0
- package/react.js +7 -0
- package/reset.d.ts +1 -0
- package/rules/best-practices.js +324 -0
- package/rules/errors.js +38 -0
- package/rules/es6.js +175 -0
- package/rules/imports.js +26 -0
- package/rules/node.js +14 -0
- package/rules/react-hooks.js +25 -0
- package/rules/react.js +387 -0
- package/rules/sort-imports.js +62 -0
- package/rules/style.js +20 -0
- package/rules/typescript.js +151 -0
- package/rules/variables.js +74 -0
- package/tsconfig.json +21 -0
- package/typescript.js +5 -15
- package/.eslintrc-base.js +0 -138
- package/.eslintrc.js +0 -17
package/rules/react.js
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import("eslint").Linter.Config}
|
|
3
|
+
*/
|
|
4
|
+
module.exports = {
|
|
5
|
+
extends: ['plugin:jsx-a11y/recommended'],
|
|
6
|
+
plugins: ['react'],
|
|
7
|
+
settings: {
|
|
8
|
+
react: {
|
|
9
|
+
version: 'detect'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
parserOptions: {
|
|
13
|
+
ecmaFeatures: {
|
|
14
|
+
jsx: true
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
// View link below for react rules documentation
|
|
18
|
+
// https://github.com/jsx-eslint/eslint-plugin-react#list-of-supported-rules
|
|
19
|
+
rules: {
|
|
20
|
+
// Specify whether double or single quotes should be used in JSX attributes
|
|
21
|
+
// https://eslint.org/docs/rules/jsx-quotes
|
|
22
|
+
'jsx-quotes': ['error', 'prefer-double'],
|
|
23
|
+
|
|
24
|
+
// Forbid the use of Proptypes
|
|
25
|
+
'react/prop-types': 'off',
|
|
26
|
+
|
|
27
|
+
// defaultProps is deprecated
|
|
28
|
+
'react/require-default-props': [
|
|
29
|
+
'error',
|
|
30
|
+
{
|
|
31
|
+
functions: 'defaultArguments'
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
|
|
35
|
+
// Forbid certain props on DOM Nodes
|
|
36
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/forbid-dom-props.md
|
|
37
|
+
'react/forbid-dom-props': ['off', { forbid: [] }],
|
|
38
|
+
|
|
39
|
+
// Enforce boolean attributes notation in JSX
|
|
40
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
|
|
41
|
+
'react/jsx-boolean-value': 'error',
|
|
42
|
+
|
|
43
|
+
// Validate closing bracket location in JSX
|
|
44
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-bracket-location.md
|
|
45
|
+
'react/jsx-closing-bracket-location': ['error', 'line-aligned'],
|
|
46
|
+
|
|
47
|
+
// Validate closing tag location in JSX
|
|
48
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-closing-tag-location.md
|
|
49
|
+
'react/jsx-closing-tag-location': 'error',
|
|
50
|
+
|
|
51
|
+
// Enforce or disallow spaces inside of curly braces in JSX attributes
|
|
52
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md
|
|
53
|
+
'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
|
|
54
|
+
|
|
55
|
+
// Validate props indentation in JSX
|
|
56
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent-props.md
|
|
57
|
+
'react/jsx-indent-props': ['error', 2],
|
|
58
|
+
|
|
59
|
+
// Validate JSX has key prop when in array or iterator
|
|
60
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-key.md
|
|
61
|
+
// Turned off because it has too many false positives
|
|
62
|
+
'react/jsx-key': 'off',
|
|
63
|
+
|
|
64
|
+
// Limit maximum of props on a single line in JSX
|
|
65
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-max-props-per-line.md
|
|
66
|
+
'react/jsx-max-props-per-line': [
|
|
67
|
+
'error',
|
|
68
|
+
{ maximum: 1, when: 'multiline' }
|
|
69
|
+
],
|
|
70
|
+
|
|
71
|
+
// Prevent usage of .bind() in JSX props
|
|
72
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-bind.md
|
|
73
|
+
'react/jsx-no-bind': [
|
|
74
|
+
'error',
|
|
75
|
+
{
|
|
76
|
+
ignoreRefs: true,
|
|
77
|
+
allowArrowFunctions: true,
|
|
78
|
+
allowFunctions: false,
|
|
79
|
+
allowBind: false,
|
|
80
|
+
ignoreDOMComponents: true
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
|
|
84
|
+
// Prevent duplicate props in JSX
|
|
85
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-duplicate-props.md
|
|
86
|
+
'react/jsx-no-duplicate-props': ['error', { ignoreCase: true }],
|
|
87
|
+
|
|
88
|
+
// Prevent usage of unwrapped JSX strings
|
|
89
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md
|
|
90
|
+
'react/jsx-no-literals': ['off', { noStrings: true }],
|
|
91
|
+
|
|
92
|
+
// Disallow undeclared variables in JSX
|
|
93
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-undef.md
|
|
94
|
+
'react/jsx-no-undef': 'error',
|
|
95
|
+
|
|
96
|
+
// Enforce PascalCase for user-defined JSX components
|
|
97
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
|
|
98
|
+
'react/jsx-pascal-case': [
|
|
99
|
+
'error',
|
|
100
|
+
{
|
|
101
|
+
allowAllCaps: true,
|
|
102
|
+
ignore: []
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
|
|
106
|
+
// Enforce defaultProps declarations alphabetical sorting
|
|
107
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-sort-default-props.md
|
|
108
|
+
'react/jsx-sort-default-props': [
|
|
109
|
+
'off',
|
|
110
|
+
{
|
|
111
|
+
ignoreCase: true
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
|
|
115
|
+
// Prevent variables used in JSX to be incorrectly marked as unused
|
|
116
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-uses-vars.md
|
|
117
|
+
'react/jsx-uses-vars': 'error',
|
|
118
|
+
|
|
119
|
+
// Prevent usage of dangerous JSX properties
|
|
120
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger.md
|
|
121
|
+
'react/no-danger': 'warn',
|
|
122
|
+
|
|
123
|
+
// Prevent usage of deprecated methods
|
|
124
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-deprecated.md
|
|
125
|
+
'react/no-deprecated': ['error'],
|
|
126
|
+
|
|
127
|
+
// Prevent direct mutation of this.state
|
|
128
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-direct-mutation-state.md
|
|
129
|
+
'react/no-direct-mutation-state': 'off',
|
|
130
|
+
|
|
131
|
+
// Prevent multiple component definition per file
|
|
132
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-multi-comp.md
|
|
133
|
+
'react/no-multi-comp': 'off',
|
|
134
|
+
|
|
135
|
+
// Prevent using string references
|
|
136
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-string-refs.md
|
|
137
|
+
'react/no-string-refs': 'error',
|
|
138
|
+
|
|
139
|
+
// Prevent usage of unknown DOM property
|
|
140
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unknown-property.md
|
|
141
|
+
'react/no-unknown-property': 'error',
|
|
142
|
+
|
|
143
|
+
// Require stateless functions when not using lifecycle methods, setState or ref
|
|
144
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md
|
|
145
|
+
'react/prefer-stateless-function': [
|
|
146
|
+
'error',
|
|
147
|
+
{ ignorePureComponents: true }
|
|
148
|
+
],
|
|
149
|
+
|
|
150
|
+
// Prevent extra closing tags for components without children
|
|
151
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
|
|
152
|
+
'react/self-closing-comp': 'error',
|
|
153
|
+
|
|
154
|
+
// Prevent missing parentheses around multilines JSX
|
|
155
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-wrap-multilines.md
|
|
156
|
+
'react/jsx-wrap-multilines': [
|
|
157
|
+
'error',
|
|
158
|
+
{
|
|
159
|
+
declaration: 'parens-new-line',
|
|
160
|
+
assignment: 'parens-new-line',
|
|
161
|
+
return: 'parens-new-line',
|
|
162
|
+
arrow: 'parens-new-line',
|
|
163
|
+
condition: 'parens-new-line',
|
|
164
|
+
logical: 'parens-new-line',
|
|
165
|
+
prop: 'parens-new-line'
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
|
|
169
|
+
// Require that the first prop in a JSX element be on a new line when the element is multiline
|
|
170
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-first-prop-new-line.md
|
|
171
|
+
'react/jsx-first-prop-new-line': ['error', 'multiline-multiprop'],
|
|
172
|
+
|
|
173
|
+
// Enforce spacing around jsx equals signs
|
|
174
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-equals-spacing.md
|
|
175
|
+
'react/jsx-equals-spacing': ['error', 'never'],
|
|
176
|
+
|
|
177
|
+
// Enforce JSX indentation
|
|
178
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-indent.md
|
|
179
|
+
'react/jsx-indent': ['error', 2],
|
|
180
|
+
|
|
181
|
+
// Disallow target="_blank" on links
|
|
182
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-no-target-blank.md
|
|
183
|
+
'react/jsx-no-target-blank': ['error', { enforceDynamicLinks: 'always' }],
|
|
184
|
+
|
|
185
|
+
// only .jsx files may have JSX
|
|
186
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-filename-extension.md
|
|
187
|
+
'react/jsx-filename-extension': ['error', { extensions: ['.jsx'] }],
|
|
188
|
+
|
|
189
|
+
// prevent accidental JS comments from being injected into JSX as text
|
|
190
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-comment-textnodes.md
|
|
191
|
+
'react/jsx-no-comment-textnodes': 'error',
|
|
192
|
+
|
|
193
|
+
// disallow using React.render/ReactDOM.render's return value
|
|
194
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-render-return-value.md
|
|
195
|
+
'react/no-render-return-value': 'error',
|
|
196
|
+
|
|
197
|
+
// Forbid certain props on Components
|
|
198
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md
|
|
199
|
+
'react/forbid-component-props': ['off', { forbid: [] }],
|
|
200
|
+
|
|
201
|
+
// Prevent problem with children and props.dangerouslySetInnerHTML
|
|
202
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-danger-with-children.md
|
|
203
|
+
'react/no-danger-with-children': 'error',
|
|
204
|
+
|
|
205
|
+
// Prevent unused propType definitions
|
|
206
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unused-prop-types.md
|
|
207
|
+
'react/no-unused-prop-types': [
|
|
208
|
+
'error',
|
|
209
|
+
{
|
|
210
|
+
customValidators: [],
|
|
211
|
+
skipShapeProps: true
|
|
212
|
+
}
|
|
213
|
+
],
|
|
214
|
+
|
|
215
|
+
// Require style prop value be an object or var
|
|
216
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/style-prop-object.md
|
|
217
|
+
'react/style-prop-object': 'error',
|
|
218
|
+
|
|
219
|
+
// Prevent invalid characters from appearing in markup
|
|
220
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unescaped-entities.md
|
|
221
|
+
'react/no-unescaped-entities': 'error',
|
|
222
|
+
|
|
223
|
+
// Prevent passing of children as props
|
|
224
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
|
|
225
|
+
'react/no-children-prop': 'error',
|
|
226
|
+
|
|
227
|
+
// Validate whitespace in and around the JSX opening and closing brackets
|
|
228
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-tag-spacing.md
|
|
229
|
+
'react/jsx-tag-spacing': [
|
|
230
|
+
'error',
|
|
231
|
+
{
|
|
232
|
+
closingSlash: 'never',
|
|
233
|
+
beforeSelfClosing: 'always',
|
|
234
|
+
afterOpening: 'never',
|
|
235
|
+
beforeClosing: 'never'
|
|
236
|
+
}
|
|
237
|
+
],
|
|
238
|
+
|
|
239
|
+
// Enforce spaces before the closing bracket of self-closing JSX elements
|
|
240
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-space-before-closing.md
|
|
241
|
+
// Deprecated in favor of jsx-tag-spacing
|
|
242
|
+
'react/jsx-space-before-closing': ['off', 'always'],
|
|
243
|
+
|
|
244
|
+
// Prevent usage of Array index in keys
|
|
245
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
|
|
246
|
+
'react/no-array-index-key': 'error',
|
|
247
|
+
|
|
248
|
+
// Prevent unused state values
|
|
249
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/pull/1103/
|
|
250
|
+
'react/no-unused-state': 'error',
|
|
251
|
+
|
|
252
|
+
// Enforces consistent naming for boolean props
|
|
253
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/boolean-prop-naming.md
|
|
254
|
+
'react/boolean-prop-naming': [
|
|
255
|
+
'off',
|
|
256
|
+
{
|
|
257
|
+
propTypeNames: ['bool', 'mutuallyExclusiveTrueProps'],
|
|
258
|
+
rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
|
|
259
|
+
message: ''
|
|
260
|
+
}
|
|
261
|
+
],
|
|
262
|
+
|
|
263
|
+
// Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children
|
|
264
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
|
|
265
|
+
'react/jsx-curly-brace-presence': [
|
|
266
|
+
'error',
|
|
267
|
+
{ props: 'never', children: 'never' }
|
|
268
|
+
],
|
|
269
|
+
|
|
270
|
+
// One JSX Element Per Line
|
|
271
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/jsx-one-expression-per-line.md
|
|
272
|
+
'react/jsx-one-expression-per-line': ['error', { allow: 'single-child' }],
|
|
273
|
+
|
|
274
|
+
// Enforce consistent usage of destructuring assignment of props, state, and context
|
|
275
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/destructuring-assignment.md
|
|
276
|
+
'react/destructuring-assignment': ['error', 'always'],
|
|
277
|
+
|
|
278
|
+
// Prevent usage of button elements without an explicit type attribute
|
|
279
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/843d71a432baf0f01f598d7cf1eea75ad6896e4b/docs/rules/button-has-type.md
|
|
280
|
+
'react/button-has-type': [
|
|
281
|
+
'error',
|
|
282
|
+
{
|
|
283
|
+
button: true,
|
|
284
|
+
submit: true,
|
|
285
|
+
reset: false
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
|
|
289
|
+
// Ensures inline tags are not rendered without spaces between them
|
|
290
|
+
'react/jsx-child-element-spacing': 'off',
|
|
291
|
+
|
|
292
|
+
// Disallow multiple spaces between inline JSX props
|
|
293
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/ac102885765be5ff37847a871f239c6703e1c7cc/docs/rules/jsx-props-no-multi-spaces.md
|
|
294
|
+
'react/jsx-props-no-multi-spaces': 'error',
|
|
295
|
+
|
|
296
|
+
// Enforce shorthand or standard form for React fragments
|
|
297
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/bc976b837abeab1dffd90ac6168b746a83fc83cc/docs/rules/jsx-fragments.md
|
|
298
|
+
'react/jsx-fragments': ['error', 'syntax'],
|
|
299
|
+
|
|
300
|
+
// Enforce linebreaks in curly braces in JSX attributes and expressions.
|
|
301
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-newline.md
|
|
302
|
+
'react/jsx-curly-newline': [
|
|
303
|
+
'error',
|
|
304
|
+
{
|
|
305
|
+
multiline: 'consistent',
|
|
306
|
+
singleline: 'consistent'
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
|
|
310
|
+
// Disallow unnecessary fragments
|
|
311
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
|
|
312
|
+
'react/jsx-no-useless-fragment': 'error',
|
|
313
|
+
|
|
314
|
+
// This rule is turned off with the new JSX transform
|
|
315
|
+
// since `eslint-plugin-react` is used.
|
|
316
|
+
// Ref: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#how-to-upgrade-to-the-new-jsx-transform
|
|
317
|
+
'react/jsx-uses-react': 'off',
|
|
318
|
+
|
|
319
|
+
// This rule is turned off with the new JSX transform
|
|
320
|
+
// since `eslint-plugin-react` is used.
|
|
321
|
+
// Ref: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html#how-to-upgrade-to-the-new-jsx-transform
|
|
322
|
+
'react/react-in-jsx-scope': 'off',
|
|
323
|
+
|
|
324
|
+
// Enforce a specific function type for function components
|
|
325
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/function-component-definition.md
|
|
326
|
+
'react/function-component-definition': [
|
|
327
|
+
'error',
|
|
328
|
+
{ namedComponents: 'arrow-function' }
|
|
329
|
+
],
|
|
330
|
+
|
|
331
|
+
// Prevent react contexts from taking non-stable values
|
|
332
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/e2eaadae316f9506d163812a09424eb42698470a/docs/rules/jsx-no-constructed-context-values.md
|
|
333
|
+
'react/jsx-no-constructed-context-values': 'error',
|
|
334
|
+
|
|
335
|
+
// Lifecycle methods should be methods on the prototype, not class fields
|
|
336
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-arrow-function-lifecycle.md
|
|
337
|
+
'react/no-arrow-function-lifecycle': 'error',
|
|
338
|
+
|
|
339
|
+
// Prevent usage of invalid attributes
|
|
340
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/21e01b61af7a38fc86d94f27eb66cda8054582ed/docs/rules/no-invalid-html-attribute.md
|
|
341
|
+
'react/no-invalid-html-attribute': 'error',
|
|
342
|
+
|
|
343
|
+
// Enforce sandbox attribute on iframe elements
|
|
344
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/c8833f301314dab3e79ef7ac4cf863e4d5fa0019/docs/rules/iframe-missing-sandbox.md
|
|
345
|
+
'react/iframe-missing-sandbox': 'error',
|
|
346
|
+
|
|
347
|
+
// Prevent problematic leaked values from being rendered
|
|
348
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/c42b624d0fb9ad647583a775ab9751091eec066f/docs/rules/jsx-no-leaked-render.md
|
|
349
|
+
'react/jsx-no-leaked-render': [
|
|
350
|
+
'error',
|
|
351
|
+
{
|
|
352
|
+
validStrategies: ['ternary']
|
|
353
|
+
}
|
|
354
|
+
],
|
|
355
|
+
|
|
356
|
+
// https://github.com/jsx-eslint/eslint-plugin-react/blob/66b58dd4864678eb869a7bf434c72ff7ac530eb1/docs/rules/no-object-type-as-default-prop.md
|
|
357
|
+
'react/no-object-type-as-default-prop': 'error',
|
|
358
|
+
|
|
359
|
+
'class-methods-use-this': [
|
|
360
|
+
'error',
|
|
361
|
+
{
|
|
362
|
+
exceptMethods: [
|
|
363
|
+
'render',
|
|
364
|
+
'componentDidCatch',
|
|
365
|
+
'getSnapshotBeforeUpdate'
|
|
366
|
+
]
|
|
367
|
+
}
|
|
368
|
+
]
|
|
369
|
+
},
|
|
370
|
+
overrides: [
|
|
371
|
+
{
|
|
372
|
+
// JSX in .tsx files instead of .jsx
|
|
373
|
+
files: ['*.ts?(x)'],
|
|
374
|
+
rules: {
|
|
375
|
+
'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }]
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
// Enable eslint-plugin-testing-library rules or preset only for matching files!
|
|
380
|
+
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
|
|
381
|
+
extends: ['plugin:testing-library/react'],
|
|
382
|
+
rules: {
|
|
383
|
+
'testing-library/render-result-naming-convention': 0
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
]
|
|
387
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { getTsconfig } = require('get-tsconfig')
|
|
2
|
+
|
|
3
|
+
function extractPaths(paths) {
|
|
4
|
+
return Object.keys(paths).map((key) => {
|
|
5
|
+
return key.split('/')[0]
|
|
6
|
+
})
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
sortImports: (path) => {
|
|
11
|
+
const tsConfig = getTsconfig(path, 'tsconfig.json')
|
|
12
|
+
const jsConfig = getTsconfig(path, 'jsconfig.json')
|
|
13
|
+
|
|
14
|
+
let pathsNames = []
|
|
15
|
+
|
|
16
|
+
if (tsConfig && tsConfig.config.compilerOptions.paths) {
|
|
17
|
+
pathsNames = extractPaths(tsConfig.config.compilerOptions.paths)
|
|
18
|
+
} else if (jsConfig && jsConfig.config.compilerOptions.paths) {
|
|
19
|
+
pathsNames = extractPaths(jsConfig.config.compilerOptions.paths)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
files: ['*.ts?(x)', '*.js?(x)'],
|
|
24
|
+
rules: {
|
|
25
|
+
'simple-import-sort/imports': [
|
|
26
|
+
'error',
|
|
27
|
+
{
|
|
28
|
+
groups: [
|
|
29
|
+
[
|
|
30
|
+
// Anything that starts with react
|
|
31
|
+
// e.g: import { useState } from 'react'
|
|
32
|
+
// e.g: import { useFela } from 'react-fela'
|
|
33
|
+
'^react',
|
|
34
|
+
// Anything that starts with next
|
|
35
|
+
// e.g: import { useRouter } from 'next/router'
|
|
36
|
+
'^next',
|
|
37
|
+
// Anything that starts with a letter
|
|
38
|
+
// e.g: import Downshift from 'downshift'
|
|
39
|
+
'^[a-z]',
|
|
40
|
+
// Anything that starts with an alias (see jsconfig.json)
|
|
41
|
+
// e.g: import ListDropdown from '@shared/components/ListDropdown'
|
|
42
|
+
`^(${pathsNames.join('|')})(/.*|$)`,
|
|
43
|
+
// Anything that starts with @
|
|
44
|
+
// e.g: import { yupResolver } from '@hookform/resolvers/yup'
|
|
45
|
+
'^@',
|
|
46
|
+
// Anything that starts with a dot
|
|
47
|
+
// e.g: import { matchIsDate } from './utils/date
|
|
48
|
+
'^\\.',
|
|
49
|
+
// Side effect imports from lib
|
|
50
|
+
// e.g: import 'react-toastify/dist/ReactToastify.css'
|
|
51
|
+
'^\\u0000',
|
|
52
|
+
// Side effect import that starts with a dot
|
|
53
|
+
// e.g: import './setup-config'
|
|
54
|
+
'^\\u0000\\.'
|
|
55
|
+
]
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/rules/style.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import("eslint").Linter.Config}
|
|
3
|
+
*/
|
|
4
|
+
module.exports = {
|
|
5
|
+
rules: {
|
|
6
|
+
'lines-between-class-members': ['error', 'always'],
|
|
7
|
+
'padding-line-between-statements': [
|
|
8
|
+
2,
|
|
9
|
+
// We always want a blank line before a `return` statement or a multi-line
|
|
10
|
+
// block.
|
|
11
|
+
{
|
|
12
|
+
blankLine: 'always',
|
|
13
|
+
prev: '*',
|
|
14
|
+
next: ['return', 'multiline-block-like']
|
|
15
|
+
},
|
|
16
|
+
// We always want a blank line after a multi-line block.
|
|
17
|
+
{ blankLine: 'always', prev: 'multiline-block-like', next: '*' }
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const { rules: baseBestPracticesRules } = require('./best-practices')
|
|
2
|
+
const { rules: baseErrorsRules } = require('./errors')
|
|
3
|
+
const { rules: baseVariablesRules } = require('./variables')
|
|
4
|
+
const { rules: baseES6Rules } = require('./es6')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @type {import("eslint").Linter.Config}
|
|
8
|
+
*/
|
|
9
|
+
module.exports = {
|
|
10
|
+
extends: ['plugin:@typescript-eslint/recommended'],
|
|
11
|
+
parser: '@typescript-eslint/parser',
|
|
12
|
+
settings: {
|
|
13
|
+
// Apply special parsing for TypeScript files
|
|
14
|
+
'import/parsers': {
|
|
15
|
+
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts']
|
|
16
|
+
},
|
|
17
|
+
// Append 'ts' extensions to Frichti 'import/resolver' setting
|
|
18
|
+
// Original: ['.mjs', '.js', '.json']
|
|
19
|
+
'import/resolver': {
|
|
20
|
+
node: {
|
|
21
|
+
extensions: ['.mjs', '.js', '.json', '.ts', '.d.ts']
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
// Append 'ts' extensions to Frichti 'import/extensions' setting
|
|
25
|
+
// Original: ['.js', '.mjs', '.jsx']
|
|
26
|
+
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],
|
|
27
|
+
// Resolve type definition packages
|
|
28
|
+
'import/external-module-folders': ['node_modules', 'node_modules/@types']
|
|
29
|
+
},
|
|
30
|
+
rules: {
|
|
31
|
+
// Replace Frichti 'default-param-last' rule with '@typescript-eslint' version
|
|
32
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/default-param-last.md
|
|
33
|
+
'default-param-last': 'off',
|
|
34
|
+
'@typescript-eslint/default-param-last':
|
|
35
|
+
baseBestPracticesRules['default-param-last'],
|
|
36
|
+
|
|
37
|
+
// Replace Frichti 'dot-notation' rule with '@typescript-eslint' version
|
|
38
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/dot-notation.md
|
|
39
|
+
'dot-notation': 'off',
|
|
40
|
+
'@typescript-eslint/dot-notation': baseBestPracticesRules['dot-notation'],
|
|
41
|
+
|
|
42
|
+
// Replace Frichti 'no-empty-function' rule with '@typescript-eslint' version
|
|
43
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
|
|
44
|
+
'no-empty-function': 'off',
|
|
45
|
+
'@typescript-eslint/no-empty-function':
|
|
46
|
+
baseBestPracticesRules['no-empty-function'],
|
|
47
|
+
|
|
48
|
+
// Replace Frichti 'no-extra-semi' rule with '@typescript-eslint' version
|
|
49
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-semi.md
|
|
50
|
+
'no-extra-semi': 'off',
|
|
51
|
+
'@typescript-eslint/no-extra-semi': baseErrorsRules['no-extra-semi'],
|
|
52
|
+
|
|
53
|
+
// Replace Frichti 'no-redeclare' rule with '@typescript-eslint' version
|
|
54
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-redeclare.md
|
|
55
|
+
'no-redeclare': 'off',
|
|
56
|
+
'@typescript-eslint/no-redeclare': baseBestPracticesRules['no-redeclare'],
|
|
57
|
+
|
|
58
|
+
// Replace Frichti 'no-shadow' rule with '@typescript-eslint' version
|
|
59
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
|
|
60
|
+
'no-shadow': 'off',
|
|
61
|
+
'@typescript-eslint/no-shadow': baseVariablesRules['no-shadow'],
|
|
62
|
+
|
|
63
|
+
// Replace Frichti 'no-throw-literal' rule with '@typescript-eslint' version
|
|
64
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-throw-literal.md
|
|
65
|
+
'no-throw-literal': 'off',
|
|
66
|
+
'@typescript-eslint/no-throw-literal':
|
|
67
|
+
baseBestPracticesRules['no-throw-literal'],
|
|
68
|
+
|
|
69
|
+
// Replace Frichti 'no-unused-expressions' rule with '@typescript-eslint' version
|
|
70
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
|
|
71
|
+
'no-unused-expressions': 'off',
|
|
72
|
+
'@typescript-eslint/no-unused-expressions':
|
|
73
|
+
baseBestPracticesRules['no-unused-expressions'],
|
|
74
|
+
|
|
75
|
+
// Replace Frichti 'no-unused-vars' rule with '@typescript-eslint' version
|
|
76
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
|
|
77
|
+
'no-unused-vars': 'off',
|
|
78
|
+
'@typescript-eslint/no-unused-vars': baseVariablesRules['no-unused-vars'],
|
|
79
|
+
|
|
80
|
+
// Replace Frichti 'no-use-before-define' rule with '@typescript-eslint' version
|
|
81
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
|
|
82
|
+
'no-use-before-define': 'off',
|
|
83
|
+
'@typescript-eslint/no-use-before-define':
|
|
84
|
+
baseVariablesRules['no-use-before-define'],
|
|
85
|
+
|
|
86
|
+
// Replace Frichti 'no-useless-constructor' rule with '@typescript-eslint' version
|
|
87
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
|
|
88
|
+
'no-useless-constructor': 'off',
|
|
89
|
+
'@typescript-eslint/no-useless-constructor':
|
|
90
|
+
baseES6Rules['no-useless-constructor'],
|
|
91
|
+
|
|
92
|
+
// Replace Frichti 'require-await' rule with '@typescript-eslint' version
|
|
93
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/require-await.md
|
|
94
|
+
'require-await': 'off',
|
|
95
|
+
'@typescript-eslint/require-await': baseES6Rules['require-await'],
|
|
96
|
+
|
|
97
|
+
// Replace Frichti 'no-return-await' rule with '@typescript-eslint' version
|
|
98
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
|
|
99
|
+
'no-return-await': 'off',
|
|
100
|
+
'@typescript-eslint/return-await': [
|
|
101
|
+
baseES6Rules['no-return-await'],
|
|
102
|
+
'in-try-catch'
|
|
103
|
+
],
|
|
104
|
+
|
|
105
|
+
// Accept banning ts lines
|
|
106
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
107
|
+
|
|
108
|
+
// Naming convention
|
|
109
|
+
'@typescript-eslint/naming-convention': [
|
|
110
|
+
'error',
|
|
111
|
+
{
|
|
112
|
+
selector: 'typeLike',
|
|
113
|
+
format: ['PascalCase']
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
overrides: [
|
|
118
|
+
{
|
|
119
|
+
files: ['*.ts?(x)'],
|
|
120
|
+
rules: {
|
|
121
|
+
// The following rules are enabled in Frichti config, but are already checked (more thoroughly) by the TypeScript compiler
|
|
122
|
+
// Some of the rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
|
|
123
|
+
// Rules are inspired by: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
|
|
124
|
+
'constructor-super': 'off',
|
|
125
|
+
'getter-return': 'off',
|
|
126
|
+
'no-const-assign': 'off',
|
|
127
|
+
'no-dupe-args': 'off',
|
|
128
|
+
'no-dupe-class-members': 'off',
|
|
129
|
+
'no-dupe-keys': 'off',
|
|
130
|
+
'no-func-assign': 'off',
|
|
131
|
+
'no-import-assign': 'off',
|
|
132
|
+
'no-new-symbol': 'off',
|
|
133
|
+
'no-obj-calls': 'off',
|
|
134
|
+
'no-redeclare': 'off',
|
|
135
|
+
'no-setter-return': 'off',
|
|
136
|
+
'no-this-before-super': 'off',
|
|
137
|
+
// https://github.com/typescript-eslint/typescript-eslint/blob/1cf9243/docs/getting-started/linting/FAQ.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
|
|
138
|
+
'no-undef': 'off',
|
|
139
|
+
'no-unreachable': 'off',
|
|
140
|
+
'no-unsafe-negation': 'off',
|
|
141
|
+
'valid-typeof': 'off',
|
|
142
|
+
// The following rules are enabled in Frichti config, but are recommended to be disabled within TypeScript projects
|
|
143
|
+
// See: https://github.com/typescript-eslint/typescript-eslint/blob/13583e65f5973da2a7ae8384493c5e00014db51b/docs/linting/TROUBLESHOOTING.md#eslint-plugin-import
|
|
144
|
+
'import/named': 'off',
|
|
145
|
+
'import/no-named-as-default-member': 'off',
|
|
146
|
+
// Disable `import/no-unresolved`, see README.md for details
|
|
147
|
+
'import/no-unresolved': 'off'
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|