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