eslint-config-react-app-new 2.0.0 → 2.0.2

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/base.js CHANGED
@@ -2,6 +2,10 @@ const react = require('eslint-plugin-react');
2
2
  const babelParser = require('@babel/eslint-parser');
3
3
  const globals = require('globals');
4
4
 
5
+ if (!process.env.NODE_ENV) {
6
+ process.env.NODE_ENV = 'development';
7
+ }
8
+
5
9
  module.exports = [
6
10
  {
7
11
  languageOptions: {
@@ -14,7 +18,7 @@ module.exports = [
14
18
  }
15
19
  },
16
20
  // true means writeable, false means readonly, 'off' means disabled
17
- gloabls: {
21
+ globals: {
18
22
  ...globals.browser,
19
23
  ...globals.node,
20
24
  ...globals.commonjs,
package/import.js ADDED
@@ -0,0 +1,52 @@
1
+ const importPlugin = require('eslint-plugin-import');
2
+
3
+ module.exports = [
4
+ {
5
+ plugins: {
6
+ import: importPlugin
7
+ },
8
+ rules: {
9
+ // https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
10
+ 'import/first': 'error',
11
+ 'import/no-anonymous-default-export': [
12
+ 'error',
13
+ {
14
+ allowArray: true,
15
+ allowArrowFunction: false,
16
+ allowAnonymousClass: false,
17
+ allowAnonymousFunction: false,
18
+ allowCallExpression: true,
19
+ allowLiteral: true,
20
+ allowObject: true,
21
+ allowNew: true
22
+ }
23
+ ],
24
+ 'import/no-duplicates': 'error',
25
+ 'import/no-webpack-loader-syntax': 'error',
26
+ 'import/order': [
27
+ 'error',
28
+ {
29
+ groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object'],
30
+ sortTypesGroup: false,
31
+ alphabetize: { order: 'asc', caseInsensitive: true },
32
+ 'newlines-between': 'never'
33
+ }
34
+ ],
35
+ // 负责 { a, b, c } 子导出顺序
36
+ 'sort-imports': [
37
+ 'warn',
38
+ {
39
+ ignoreCase: true,
40
+ ignoreDeclarationSort: true,
41
+ ignoreMemberSort: false
42
+ }
43
+ ],
44
+ 'import/no-useless-path-segments': [
45
+ 'error',
46
+ {
47
+ noUselessIndex: true
48
+ }
49
+ ]
50
+ }
51
+ }
52
+ ];
package/index.js CHANGED
@@ -4,16 +4,18 @@ const baseConfig = require('./base');
4
4
  const reactConfig = require('./react');
5
5
  const jsxA11yConfig = require('./jsx-a11y');
6
6
  const importConfig = require('./import');
7
+ const jestConfig = require('./jest');
7
8
 
8
9
  module.exports = [
10
+ baseConfig,
11
+ reactConfig,
12
+ jsxA11yConfig,
13
+ importConfig,
14
+ jestConfig,
9
15
  {
10
- extends: [baseConfig, reactConfig, jsxA11yConfig, importConfig],
11
- // NOTE: When adding rules here, you need to make sure they are compatible with
12
- // `typescript-eslint`, as some rules such as `no-array-constructor` aren't compatible.
13
16
  rules: {
14
- // http://eslint.org/docs/rules/
15
17
  'array-callback-return': 'warn',
16
- 'default-case': ['warn', { commentPattern: '^no default$' }],
18
+ 'default-case': ['warn', { commentPattern: '^no[-\\s]+default$' }],
17
19
  'dot-location': ['warn', 'property'],
18
20
  eqeqeq: ['warn', 'smart'],
19
21
  'new-parens': 'warn',
@@ -93,8 +95,13 @@ module.exports = [
93
95
  'no-unused-vars': [
94
96
  'warn',
95
97
  {
96
- args: 'none',
97
- ignoreRestSiblings: true
98
+ vars: 'all',
99
+ args: 'after-used',
100
+ caughtErrors: 'none',
101
+ ignoreRestSiblings: true,
102
+ varsIgnorePattern: '^_',
103
+ destructuredArrayIgnorePattern: '^_',
104
+ argsIgnorePattern: '^_|^err|^ev'
98
105
  }
99
106
  ],
100
107
  'no-use-before-define': [
@@ -141,21 +148,110 @@ module.exports = [
141
148
  'Please use import() instead. More info: https://facebook.github.io/create-react-app/docs/code-splitting'
142
149
  }
143
150
  ],
144
- 'getter-return': 'warn'
145
- }
146
- },
147
- {
148
- files: ['app/**/*'],
149
- rules: {
150
- 'no-console': 'warn'
151
+ 'getter-return': 'warn',
152
+ 'linebreak-style': ['warn', 'unix'],
153
+ 'semi-spacing': ['warn', { before: false }],
154
+ 'no-extra-semi': 'warn',
155
+ 'padded-blocks': ['warn', 'never'],
156
+ 'one-var-declaration-per-line': ['warn', 'initializations'],
157
+ 'spaced-comment': ['warn', 'always'],
158
+ 'space-in-parens': ['warn', 'never'],
159
+ 'space-before-function-paren': [
160
+ 'warn',
161
+ {
162
+ anonymous: 'never',
163
+ named: 'never',
164
+ asyncArrow: 'always'
165
+ }
166
+ ],
167
+ 'space-unary-ops': 'warn',
168
+ 'space-infix-ops': 'warn',
169
+ 'space-before-blocks': 'warn',
170
+ 'no-trailing-spaces': ['warn', { ignoreComments: true }],
171
+ 'key-spacing': ['warn', { mode: 'strict' }],
172
+ 'switch-colon-spacing': 'warn',
173
+ 'func-call-spacing': ['warn', 'never'],
174
+ 'keyword-spacing': 'warn',
175
+ 'no-multiple-empty-lines': [
176
+ 'warn',
177
+ {
178
+ max: 1,
179
+ maxEOF: 0,
180
+ maxBOF: 0
181
+ }
182
+ ],
183
+ 'default-param-last': 'error',
184
+ curly: 'error',
185
+ 'dot-notation': 'warn',
186
+ 'symbol-description': 'error',
187
+ 'prefer-template': 'warn',
188
+ 'no-unexpected-multiline': 'warn',
189
+ 'no-else-return': 'warn',
190
+ 'guard-for-in': 'error',
191
+ 'no-multi-spaces': [
192
+ 'warn',
193
+ {
194
+ ignoreEOLComments: true,
195
+ exceptions: {
196
+ VariableDeclarator: true,
197
+ ImportDeclaration: true
198
+ }
199
+ }
200
+ ],
201
+ 'no-floating-decimal': 'warn',
202
+ yoda: 'warn',
203
+ 'no-unmodified-loop-condition': 'warn',
204
+ 'wrap-iife': ['error', 'inside'],
205
+ 'lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
206
+ 'padding-line-between-statements': [
207
+ 'warn',
208
+ {
209
+ blankLine: 'always',
210
+ prev: [
211
+ 'multiline-block-like',
212
+ 'multiline-expression',
213
+ 'const',
214
+ 'let',
215
+ 'var',
216
+ 'cjs-import',
217
+ 'import',
218
+ 'export',
219
+ 'cjs-export',
220
+ 'class',
221
+ 'throw',
222
+ 'directive'
223
+ ],
224
+ next: '*'
225
+ },
226
+ {
227
+ blankLine: 'always',
228
+ prev: '*',
229
+ next: [
230
+ 'multiline-block-like',
231
+ 'multiline-expression',
232
+ 'const',
233
+ 'let',
234
+ 'var',
235
+ 'cjs-import',
236
+ 'import',
237
+ 'export',
238
+ 'cjs-export',
239
+ 'class',
240
+ 'throw',
241
+ 'return'
242
+ ]
243
+ },
244
+ { blankLine: 'any', prev: ['cjs-import', 'import'], next: ['cjs-import', 'import'] },
245
+ { blankLine: 'any', prev: ['export', 'cjs-export'], next: ['export', 'cjs-export'] },
246
+ { blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] }
247
+ ]
151
248
  }
152
249
  },
153
250
  {
154
251
  files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
155
252
  plugins: {
156
- '@typescript-eslint': tseslint
253
+ '@typescript-eslint': tseslint.plugin
157
254
  },
158
- extends: ['@typescript-eslint/eslint-recommended'],
159
255
  languageOptions: {
160
256
  parser: tseslint.parser,
161
257
  sourceType: 'module',
@@ -170,13 +266,76 @@ module.exports = [
170
266
  }
171
267
  },
172
268
  rules: {
173
- // TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906)
269
+ ...tseslint.configs.eslintRecommended.rules,
174
270
  'default-case': 'off',
175
- // Add TypeScript specific rules (and turn off ESLint equivalents)
271
+ '@typescript-eslint/ban-tslint-comment': 'warn',
176
272
  '@typescript-eslint/consistent-type-assertions': 'warn',
177
- 'no-array-constructor': 'off',
178
- '@typescript-eslint/no-array-constructor': 'warn',
179
- '@typescript-eslint/no-redeclare': 'warn',
273
+ '@typescript-eslint/adjacent-overload-signatures': 'error',
274
+ '@typescript-eslint/array-type': [
275
+ 'warn',
276
+ {
277
+ default: 'array-simple'
278
+ }
279
+ ],
280
+ '@typescript-eslint/class-literal-property-style': 'warn',
281
+ '@typescript-eslint/consistent-indexed-object-style': 'warn',
282
+ '@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
283
+ '@typescript-eslint/naming-convention': [
284
+ 'error',
285
+ {
286
+ selector: 'typeLike',
287
+ format: ['PascalCase']
288
+ }
289
+ ],
290
+ '@typescript-eslint/no-confusing-non-null-assertion': 'warn',
291
+ '@typescript-eslint/no-duplicate-enum-values': 'error',
292
+ '@typescript-eslint/no-extra-non-null-assertion': 'error',
293
+ '@typescript-eslint/no-extraneous-class': 'error',
294
+ '@typescript-eslint/no-invalid-void-type': 'error',
295
+ '@typescript-eslint/no-import-type-side-effects': 'error',
296
+ '@typescript-eslint/no-misused-new': 'error',
297
+ '@typescript-eslint/no-namespace': 'error',
298
+ '@typescript-eslint/no-non-null-asserted-optional-chain': 'warn',
299
+ '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'warn',
300
+ '@typescript-eslint/no-unnecessary-type-constraint': 'error',
301
+ '@typescript-eslint/no-unsafe-declaration-merging': 'error',
302
+ '@typescript-eslint/no-empty-object-type': [
303
+ 'error',
304
+ {
305
+ allowInterfaces: 'never',
306
+ allowObjectTypes: 'always'
307
+ }
308
+ ],
309
+ '@typescript-eslint/no-redeclare': [
310
+ 'error',
311
+ {
312
+ ignoreDeclarationMerge: true
313
+ }
314
+ ],
315
+ '@typescript-eslint/no-require-imports': ['error', {
316
+ allowAsImport: false
317
+ }],
318
+ '@typescript-eslint/no-this-alias': [
319
+ 'error',
320
+ {
321
+ allowDestructuring: true, // Allow `const { props, state } = this`; false by default
322
+ allowedNames: ['self'] // Allow `const self = this`; `[]` by default
323
+ }
324
+ ],
325
+ '@typescript-eslint/no-wrapper-object-types': 'error',
326
+ '@typescript-eslint/prefer-as-const': 'warn',
327
+ '@typescript-eslint/prefer-literal-enum-member': 'error',
328
+ '@typescript-eslint/prefer-as-const': 'error',
329
+ '@typescript-eslint/prefer-namespace-keyword': 'error',
330
+ '@typescript-eslint/triple-slash-reference': 'error',
331
+ '@typescript-eslint/unified-signatures': 'warn',
332
+
333
+ 'default-param-last': 'off',
334
+ '@typescript-eslint/default-param-last': 'error',
335
+
336
+ 'no-loop-func': 'off',
337
+ '@typescript-eslint/no-loop-func': 'warn',
338
+
180
339
  'no-use-before-define': 'off',
181
340
  '@typescript-eslint/no-use-before-define': [
182
341
  'warn',
@@ -187,6 +346,7 @@ module.exports = [
187
346
  typedefs: false
188
347
  }
189
348
  ],
349
+
190
350
  'no-unused-expressions': 'off',
191
351
  '@typescript-eslint/no-unused-expressions': [
192
352
  'error',
@@ -196,14 +356,24 @@ module.exports = [
196
356
  allowTaggedTemplates: true
197
357
  }
198
358
  ],
359
+
199
360
  'no-unused-vars': 'off',
200
361
  '@typescript-eslint/no-unused-vars': [
201
362
  'warn',
202
363
  {
203
- args: 'none',
204
- ignoreRestSiblings: true
364
+ vars: 'all',
365
+ args: 'after-used',
366
+ caughtErrors: 'none',
367
+ ignoreRestSiblings: true,
368
+ varsIgnorePattern: '^_',
369
+ destructuredArrayIgnorePattern: '^_',
370
+ argsIgnorePattern: '^_|^err|^ev'
205
371
  }
206
372
  ],
373
+
374
+ 'no-array-constructor': 'off',
375
+ '@typescript-eslint/no-array-constructor': 'warn',
376
+
207
377
  'no-useless-constructor': 'off',
208
378
  '@typescript-eslint/no-useless-constructor': 'warn'
209
379
  }
package/jest.js CHANGED
@@ -32,17 +32,16 @@ module.exports = [
32
32
  'jest/valid-title': 'warn',
33
33
 
34
34
  // https://github.com/testing-library/eslint-plugin-testing-library
35
- 'testing-library/await-async-query': 'error',
35
+ 'testing-library/await-async-queries': 'error',
36
36
  'testing-library/await-async-utils': 'error',
37
- 'testing-library/no-await-sync-query': 'error',
37
+ 'testing-library/no-await-sync-queries': 'error',
38
38
  'testing-library/no-container': 'error',
39
39
  'testing-library/no-debugging-utils': 'error',
40
40
  'testing-library/no-dom-import': ['error', 'react'],
41
41
  'testing-library/no-node-access': 'error',
42
42
  'testing-library/no-promise-in-fire-event': 'error',
43
- 'testing-library/no-render-in-setup': 'error',
43
+ 'testing-library/no-render-in-lifecycle': 'error',
44
44
  'testing-library/no-unnecessary-act': 'error',
45
- 'testing-library/no-wait-for-empty-callback': 'error',
46
45
  'testing-library/no-wait-for-multiple-assertions': 'error',
47
46
  'testing-library/no-wait-for-side-effects': 'error',
48
47
  'testing-library/no-wait-for-snapshot': 'error',
package/jsx-a11y.js ADDED
@@ -0,0 +1,34 @@
1
+ const a11yPlugin = require('eslint-plugin-jsx-a11y');
2
+
3
+ module.exports = [
4
+ {
5
+ plugins: {
6
+ 'jsx-a11y': a11yPlugin
7
+ },
8
+ rules: {
9
+ // https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules
10
+ 'jsx-a11y/alt-text': 'warn',
11
+ 'jsx-a11y/anchor-has-content': 'warn',
12
+ 'jsx-a11y/anchor-is-valid': [
13
+ 'warn',
14
+ {
15
+ aspects: ['noHref', 'invalidHref']
16
+ }
17
+ ],
18
+ 'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
19
+ 'jsx-a11y/aria-props': 'warn',
20
+ 'jsx-a11y/aria-proptypes': 'warn',
21
+ 'jsx-a11y/aria-role': ['warn', { ignoreNonDOM: true }],
22
+ 'jsx-a11y/aria-unsupported-elements': 'warn',
23
+ 'jsx-a11y/heading-has-content': 'warn',
24
+ 'jsx-a11y/iframe-has-title': 'warn',
25
+ 'jsx-a11y/img-redundant-alt': 'warn',
26
+ 'jsx-a11y/no-access-key': 'warn',
27
+ 'jsx-a11y/no-distracting-elements': 'warn',
28
+ 'jsx-a11y/no-redundant-roles': 'warn',
29
+ 'jsx-a11y/role-has-required-aria-props': 'warn',
30
+ 'jsx-a11y/role-supports-aria-props': 'warn',
31
+ 'jsx-a11y/scope': 'warn'
32
+ }
33
+ }
34
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-config-react-app-new",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "ESLint configuration used by tiger-new",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,7 +10,10 @@
10
10
  "files": [
11
11
  "base.js",
12
12
  "index.js",
13
- "jest.js"
13
+ "jest.js",
14
+ "react.js",
15
+ "jsx-a11y.js",
16
+ "import.js"
14
17
  ],
15
18
  "dependencies": {
16
19
  "@babel/core": "^7.28.5",
package/react.js ADDED
@@ -0,0 +1,66 @@
1
+ const react = require('eslint-plugin-react');
2
+ const reactHooksPlugin = require('eslint-plugin-react-hooks');
3
+
4
+ const hasJsxRuntime = (() => {
5
+ try {
6
+ require.resolve('react/jsx-runtime');
7
+
8
+ return true;
9
+ } catch {}
10
+
11
+ return false;
12
+ })();
13
+
14
+ module.exports = [
15
+ {
16
+ plugins: {
17
+ react,
18
+ 'react-hooks': reactHooksPlugin
19
+ },
20
+ settings: {
21
+ react: {
22
+ version: 'detect'
23
+ }
24
+ },
25
+ rules: {
26
+ // https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
27
+ 'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
28
+ 'react/forward-ref-uses-ref': 'warn',
29
+ 'react/jsx-boolean-value': [
30
+ 'warn',
31
+ 'never',
32
+ {
33
+ always: ['value']
34
+ }
35
+ ],
36
+ 'react/jsx-key': ['warn', { checkFragmentShorthand: true, warnOnDuplicates: true }],
37
+ 'react/jsx-no-comment-textnodes': 'warn',
38
+ 'react/jsx-no-duplicate-props': 'warn',
39
+ 'react/jsx-no-undef': 'error',
40
+ 'react/jsx-pascal-case': [
41
+ 'warn',
42
+ {
43
+ allowAllCaps: true,
44
+ ignore: []
45
+ }
46
+ ],
47
+ 'react/jsx-uses-react': hasJsxRuntime ? 'off' : 'warn',
48
+ 'react/jsx-uses-vars': 'warn',
49
+ 'react/no-arrow-function-lifecycle': 'error',
50
+ 'react/no-danger-with-children': 'warn',
51
+ 'react/no-deprecated': 'error',
52
+ 'react/no-direct-mutation-state': 'warn',
53
+ 'react/no-is-mounted': 'warn',
54
+ 'react/no-string-refs': ['warn', { noTemplateLiterals: true }],
55
+ 'react/no-this-in-sfc': 'error',
56
+ 'react/no-typos': 'error',
57
+ 'react/no-unsafe': ['error', { checkAliases: true }],
58
+ 'react/react-in-jsx-scope': hasJsxRuntime ? 'off' : 'warn',
59
+ 'react/require-render-return': 'error',
60
+ 'react/style-prop-object': 'warn',
61
+
62
+ ...reactHooksPlugin.configs.recommended.rules,
63
+ 'react-hooks/refs': 'off'
64
+ }
65
+ }
66
+ ];