@foray1010/eslint-config 12.2.4 → 12.3.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/CHANGELOG.md +17 -0
- package/bases/base.mjs +36 -65
- package/bases/browser.mjs +6 -10
- package/bases/prettier.mjs +5 -12
- package/bases/react.mjs +2 -12
- package/package.json +13 -14
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [12.3.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@12.3.0...@foray1010/eslint-config@12.3.1) (2024-07-25)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **deps:** update dependency eslint-plugin-unicorn to v55 ([eb62a86](https://github.com/foray1010/common-presets/commit/eb62a867cd3a5505195f6434f6e1948ce786c9c4))
|
|
11
|
+
- **eslint-config:** does not work on project without typescript installed ([8c8968d](https://github.com/foray1010/common-presets/commit/8c8968d8c43c368111652b07109782bf4daa0166))
|
|
12
|
+
|
|
13
|
+
## [12.3.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@12.2.4...@foray1010/eslint-config@12.3.0) (2024-07-21)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- **eslint-config:** migrate eslint plugin from import to import-x ([ae44cee](https://github.com/foray1010/common-presets/commit/ae44ceefa797f0afbe690c337baf7ecd58420ea9))
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
- **deps:** update dependency eslint-plugin-compat to v6 ([e7676b2](https://github.com/foray1010/common-presets/commit/e7676b2b3506cb4d92e512d40f487e007f64bd30))
|
|
22
|
+
|
|
6
23
|
## [12.2.4](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@12.2.3...@foray1010/eslint-config@12.2.4) (2024-06-15)
|
|
7
24
|
|
|
8
25
|
### Bug Fixes
|
package/bases/base.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import js from '@eslint/js'
|
|
2
2
|
import eslintPluginEslintComments from '@eslint-community/eslint-plugin-eslint-comments'
|
|
3
3
|
import { hasDep, isESM } from '@foray1010/common-presets-utils'
|
|
4
|
-
import
|
|
4
|
+
import eslintPluginImportX from 'eslint-plugin-import-x'
|
|
5
5
|
import eslintPluginJest from 'eslint-plugin-jest'
|
|
6
6
|
import eslintPluginRegexp from 'eslint-plugin-regexp'
|
|
7
7
|
import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
|
|
@@ -21,23 +21,23 @@ async function generateTypeScriptConfig() {
|
|
|
21
21
|
// typescript plugins are depended on `typescript` package
|
|
22
22
|
if (!hasDep('typescript')) return []
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
await import('@typescript-eslint/eslint-plugin')
|
|
27
|
-
).default
|
|
28
|
-
const typescriptEslintParser = (await import('@typescript-eslint/parser'))
|
|
29
|
-
.default
|
|
30
|
-
/* eslint-enable import/no-unresolved */
|
|
24
|
+
// eslint-disable-next-line import-x/no-unresolved
|
|
25
|
+
const tseslint = (await import('typescript-eslint')).default
|
|
31
26
|
const eslintPluginDeprecation = (await import('eslint-plugin-deprecation'))
|
|
32
27
|
.default
|
|
33
28
|
const eslintPluginFunctional = (await import('eslint-plugin-functional'))
|
|
34
29
|
.default
|
|
35
30
|
|
|
36
31
|
return [
|
|
37
|
-
|
|
32
|
+
// @ts-expect-error `Type 'Config' is not assignable to type 'Readonly<FlatConfig<RulesRecord>>' with 'exactOptionalPropertyTypes: true'`
|
|
33
|
+
...tseslint.config({
|
|
38
34
|
files: typeScriptFileGlobs,
|
|
35
|
+
extends: [
|
|
36
|
+
tseslint.configs.eslintRecommended,
|
|
37
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
38
|
+
esmConfig,
|
|
39
|
+
],
|
|
39
40
|
languageOptions: {
|
|
40
|
-
parser: typescriptEslintParser,
|
|
41
41
|
parserOptions: {
|
|
42
42
|
// faster linting on cli
|
|
43
43
|
// https://github.com/typescript-eslint/typescript-eslint/issues/3528
|
|
@@ -47,30 +47,16 @@ async function generateTypeScriptConfig() {
|
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
49
|
settings: {
|
|
50
|
-
'import/resolver': {
|
|
50
|
+
'import-x/resolver': {
|
|
51
51
|
typescript: true,
|
|
52
52
|
},
|
|
53
53
|
},
|
|
54
54
|
plugins: {
|
|
55
|
-
// @ts-expect-error
|
|
56
|
-
'@typescript-eslint': eslintPluginTypescriptEslint,
|
|
57
|
-
// @ts-expect-error
|
|
58
55
|
deprecation: eslintPluginDeprecation,
|
|
59
|
-
// @ts-expect-error
|
|
60
56
|
functional: eslintPluginFunctional,
|
|
61
57
|
},
|
|
62
58
|
rules: {
|
|
63
|
-
...
|
|
64
|
-
'eslint-recommended'
|
|
65
|
-
]?.overrides?.reduce(
|
|
66
|
-
(acc, override) => ({ ...acc, ...override.rules }),
|
|
67
|
-
{},
|
|
68
|
-
),
|
|
69
|
-
...eslintPluginTypescriptEslint.configs['recommended']?.rules,
|
|
70
|
-
...eslintPluginTypescriptEslint.configs[
|
|
71
|
-
'recommended-requiring-type-checking'
|
|
72
|
-
]?.rules,
|
|
73
|
-
...eslintPluginImport.configs['typescript']?.rules,
|
|
59
|
+
...eslintPluginImportX.configs['typescript']?.rules,
|
|
74
60
|
// extend existing rule
|
|
75
61
|
'@typescript-eslint/ban-types': [
|
|
76
62
|
'error',
|
|
@@ -230,14 +216,10 @@ async function generateTypeScriptConfig() {
|
|
|
230
216
|
// It is disabled in recommended config but re-enabled here to enforce a subset of global variables that supported by both node.js and browsers
|
|
231
217
|
'no-undef': 'error',
|
|
232
218
|
},
|
|
233
|
-
},
|
|
219
|
+
}),
|
|
220
|
+
// @ts-expect-error As previous item's type is not correct, this item is affected too
|
|
234
221
|
{
|
|
235
222
|
files: typeScriptTestFileGlobs,
|
|
236
|
-
plugins: {
|
|
237
|
-
// @ts-expect-error
|
|
238
|
-
'@typescript-eslint': eslintPluginTypescriptEslint,
|
|
239
|
-
jest: eslintPluginJest,
|
|
240
|
-
},
|
|
241
223
|
rules: {
|
|
242
224
|
// doesn't work with jest.fn<void>()
|
|
243
225
|
'@typescript-eslint/no-invalid-void-type': 'off',
|
|
@@ -247,10 +229,6 @@ async function generateTypeScriptConfig() {
|
|
|
247
229
|
'jest/unbound-method': ['error', { ignoreStatic: true }],
|
|
248
230
|
},
|
|
249
231
|
},
|
|
250
|
-
{
|
|
251
|
-
files: typeScriptFileGlobs,
|
|
252
|
-
...esmConfig,
|
|
253
|
-
},
|
|
254
232
|
]
|
|
255
233
|
}
|
|
256
234
|
|
|
@@ -285,6 +263,7 @@ const esmConfig = {
|
|
|
285
263
|
/** @type {EslintConfig} */
|
|
286
264
|
const baseConfig = [
|
|
287
265
|
js.configs.recommended,
|
|
266
|
+
eslintPluginRegexp.configs['flat/recommended'],
|
|
288
267
|
{
|
|
289
268
|
languageOptions: {
|
|
290
269
|
ecmaVersion: 2023,
|
|
@@ -299,19 +278,13 @@ const baseConfig = [
|
|
|
299
278
|
},
|
|
300
279
|
plugins: {
|
|
301
280
|
'@eslint-community/eslint-comments': eslintPluginEslintComments,
|
|
302
|
-
|
|
303
|
-
|
|
281
|
+
// @ts-expect-error Type is not compact with flat config
|
|
282
|
+
'import-x': eslintPluginImportX,
|
|
304
283
|
unicorn: eslintPluginUnicorn,
|
|
305
284
|
},
|
|
306
285
|
rules: {
|
|
307
286
|
...eslintPluginEslintComments.configs['recommended']?.rules,
|
|
308
|
-
...
|
|
309
|
-
...(() => {
|
|
310
|
-
const rules = eslintPluginRegexp.configs['recommended']?.rules
|
|
311
|
-
return /** @type {import('eslint').Linter.RulesRecord} */ (
|
|
312
|
-
/** @type {unknown} */ (rules)
|
|
313
|
-
)
|
|
314
|
-
})(),
|
|
287
|
+
...eslintPluginImportX.configs['recommended']?.rules,
|
|
315
288
|
...Object.fromEntries(
|
|
316
289
|
Object.entries(
|
|
317
290
|
eslintPluginUnicorn.configs['flat/recommended']?.rules ?? {},
|
|
@@ -333,9 +306,9 @@ const baseConfig = [
|
|
|
333
306
|
// always use named function for easier to debug via stack trace
|
|
334
307
|
'func-names': ['error', 'as-needed'],
|
|
335
308
|
// this rule doesn't support commonjs, some dependencies are using commonjs
|
|
336
|
-
'import/default': 'off',
|
|
309
|
+
'import-x/default': 'off',
|
|
337
310
|
// enforce extensions for both cjs and esm
|
|
338
|
-
'import/extensions': [
|
|
311
|
+
'import-x/extensions': [
|
|
339
312
|
'error',
|
|
340
313
|
// https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_mandatory_file_extensions
|
|
341
314
|
'always',
|
|
@@ -350,12 +323,12 @@ const baseConfig = [
|
|
|
350
323
|
},
|
|
351
324
|
],
|
|
352
325
|
// make sure import statements above the others
|
|
353
|
-
'import/first': 'error',
|
|
326
|
+
'import-x/first': 'error',
|
|
354
327
|
// separate import statements from the others
|
|
355
|
-
'import/newline-after-import': 'error',
|
|
328
|
+
'import-x/newline-after-import': 'error',
|
|
356
329
|
// avoid anonymous function or class for easier to debug via stack trace
|
|
357
330
|
// for other types, enforcing named data can improve autocomplete when importing
|
|
358
|
-
'import/no-anonymous-default-export': [
|
|
331
|
+
'import-x/no-anonymous-default-export': [
|
|
359
332
|
'error',
|
|
360
333
|
{
|
|
361
334
|
allowArray: false,
|
|
@@ -368,7 +341,7 @@ const baseConfig = [
|
|
|
368
341
|
},
|
|
369
342
|
],
|
|
370
343
|
// no circular dependency
|
|
371
|
-
'import/no-cycle': [
|
|
344
|
+
'import-x/no-cycle': [
|
|
372
345
|
'error',
|
|
373
346
|
{
|
|
374
347
|
// speed up linting time
|
|
@@ -376,7 +349,7 @@ const baseConfig = [
|
|
|
376
349
|
},
|
|
377
350
|
],
|
|
378
351
|
// do not allow import packages that are not listed in dependencies or peerDependencies
|
|
379
|
-
'import/no-extraneous-dependencies': [
|
|
352
|
+
'import-x/no-extraneous-dependencies': [
|
|
380
353
|
'error',
|
|
381
354
|
{
|
|
382
355
|
devDependencies: [
|
|
@@ -387,9 +360,9 @@ const baseConfig = [
|
|
|
387
360
|
},
|
|
388
361
|
],
|
|
389
362
|
// forbid a module from importing itself
|
|
390
|
-
'import/no-self-import': 'error',
|
|
363
|
+
'import-x/no-self-import': 'error',
|
|
391
364
|
// use the shortest path in import statement, but allow /index because it will be standard to omit index as default file in directory
|
|
392
|
-
'import/no-useless-path-segments': [
|
|
365
|
+
'import-x/no-useless-path-segments': [
|
|
393
366
|
'error',
|
|
394
367
|
{
|
|
395
368
|
commonjs: true,
|
|
@@ -397,9 +370,10 @@ const baseConfig = [
|
|
|
397
370
|
},
|
|
398
371
|
],
|
|
399
372
|
// turn off these rules as they do not support flat config: https://github.com/import-js/eslint-plugin-import/issues/2556
|
|
400
|
-
|
|
401
|
-
'import/
|
|
402
|
-
'import/no-named-as-default
|
|
373
|
+
// Getting this error for eslint-plugin-import-x: `sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options. (undefined:undefined)`
|
|
374
|
+
'import-x/namespace': 'off',
|
|
375
|
+
'import-x/no-named-as-default': 'off',
|
|
376
|
+
'import-x/no-named-as-default-member': 'off',
|
|
403
377
|
// prefer explicitly convert type for readability
|
|
404
378
|
'no-implicit-coercion': 'error',
|
|
405
379
|
// make sure private class members are in-use
|
|
@@ -447,15 +421,12 @@ const baseConfig = [
|
|
|
447
421
|
},
|
|
448
422
|
{
|
|
449
423
|
files: testFileGlobs,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
},
|
|
424
|
+
...eslintPluginJest.configs['flat/recommended'],
|
|
425
|
+
...eslintPluginJest.configs['flat/style'],
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
files: testFileGlobs,
|
|
456
429
|
rules: {
|
|
457
|
-
...eslintPluginJest.configs['recommended']?.rules,
|
|
458
|
-
...eslintPluginJest.configs['style']?.rules,
|
|
459
430
|
// make sure lifecycle hooks on the top for readability
|
|
460
431
|
'jest/prefer-hooks-on-top': 'error',
|
|
461
432
|
},
|
package/bases/browser.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hasDep } from '@foray1010/common-presets-utils'
|
|
2
2
|
import restrictedGlobals from 'confusing-browser-globals'
|
|
3
3
|
import eslintPluginCompat from 'eslint-plugin-compat'
|
|
4
|
-
import
|
|
4
|
+
import eslintPluginImportX from 'eslint-plugin-import-x'
|
|
5
5
|
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
|
|
6
6
|
import globals from 'globals'
|
|
7
7
|
|
|
@@ -19,12 +19,7 @@ async function generateJestDomConfig() {
|
|
|
19
19
|
return [
|
|
20
20
|
{
|
|
21
21
|
files: testFileGlobs,
|
|
22
|
-
|
|
23
|
-
'jest-dom': eslintPluginJestDom,
|
|
24
|
-
},
|
|
25
|
-
rules: {
|
|
26
|
-
...eslintPluginJestDom.configs['recommended']?.rules,
|
|
27
|
-
},
|
|
22
|
+
...eslintPluginJestDom.configs['flat/recommended'],
|
|
28
23
|
},
|
|
29
24
|
]
|
|
30
25
|
}
|
|
@@ -42,12 +37,13 @@ const browserConfig = [
|
|
|
42
37
|
},
|
|
43
38
|
plugins: {
|
|
44
39
|
compat: eslintPluginCompat,
|
|
45
|
-
|
|
40
|
+
// @ts-expect-error Type is not compact with flat config
|
|
41
|
+
'import-x': eslintPluginImportX,
|
|
46
42
|
},
|
|
47
43
|
rules: {
|
|
48
44
|
'compat/compat': 'error',
|
|
49
45
|
// frontend environment doesn't support node.js modules
|
|
50
|
-
'import/no-nodejs-modules': 'error',
|
|
46
|
+
'import-x/no-nodejs-modules': 'error',
|
|
51
47
|
'no-restricted-globals': ['error', ...restrictedGlobals],
|
|
52
48
|
},
|
|
53
49
|
},
|
|
@@ -60,7 +56,7 @@ const browserConfig = [
|
|
|
60
56
|
rules: {
|
|
61
57
|
...eslintPluginTestingLibrary.configs['dom']?.rules,
|
|
62
58
|
// allow to use nodejs modules in tests
|
|
63
|
-
'import/no-nodejs-modules': 'off',
|
|
59
|
+
'import-x/no-nodejs-modules': 'off',
|
|
64
60
|
},
|
|
65
61
|
},
|
|
66
62
|
]
|
package/bases/prettier.mjs
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
// eslint-disable-next-line import-x/extensions
|
|
2
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
|
|
3
3
|
|
|
4
4
|
/** @typedef {import('../types/internal.d.ts').EslintConfig} EslintConfig */
|
|
5
5
|
|
|
6
6
|
/** @type {EslintConfig} */
|
|
7
|
+
// should be placed at the end to override other configs
|
|
7
8
|
const prettierConfig = [
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
plugins: {
|
|
11
|
-
prettier: eslintPluginPrettier,
|
|
12
|
-
},
|
|
13
|
-
rules: {
|
|
14
|
-
...eslintConfigPrettier.rules,
|
|
15
|
-
...eslintPluginPrettier.configs['recommended']?.rules,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
9
|
+
// This includes `eslint-config-prettier` as peer dependency
|
|
10
|
+
eslintPluginPrettierRecommended,
|
|
18
11
|
]
|
|
19
12
|
export default prettierConfig
|
package/bases/react.mjs
CHANGED
|
@@ -8,28 +8,18 @@ import { testFileGlobs } from '../constants.mjs'
|
|
|
8
8
|
|
|
9
9
|
/** @type {EslintConfig} */
|
|
10
10
|
const reactConfig = [
|
|
11
|
+
eslintPluginReact.configs.flat.recommended,
|
|
12
|
+
eslintPluginReact.configs.flat['jsx-runtime'],
|
|
11
13
|
{
|
|
12
|
-
languageOptions: {
|
|
13
|
-
parserOptions: {
|
|
14
|
-
ecmaFeatures: {
|
|
15
|
-
jsx: true,
|
|
16
|
-
},
|
|
17
|
-
// copied from `eslintPluginReact.configs['jsx-runtime']`
|
|
18
|
-
jsxPragma: null, // for @typescript-eslint/parser
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
14
|
settings: {
|
|
22
15
|
react: {
|
|
23
16
|
version: 'detect',
|
|
24
17
|
},
|
|
25
18
|
},
|
|
26
19
|
plugins: {
|
|
27
|
-
react: eslintPluginReact,
|
|
28
20
|
'react-hooks': eslintPluginReactHooks,
|
|
29
21
|
},
|
|
30
22
|
rules: {
|
|
31
|
-
...eslintPluginReact.configs['recommended']?.rules,
|
|
32
|
-
...eslintPluginReact.configs['jsx-runtime']?.rules,
|
|
33
23
|
...eslintPluginReactHooks.configs['recommended']?.rules,
|
|
34
24
|
// avoid unexpected form submits
|
|
35
25
|
'react/button-has-type': 'error',
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@foray1010/eslint-config",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.3.1",
|
|
5
5
|
"homepage": "https://github.com/foray1010/common-presets/tree/master/packages/eslint-config#readme",
|
|
6
6
|
"bugs": "https://github.com/foray1010/common-presets/issues",
|
|
7
7
|
"repository": {
|
|
@@ -23,26 +23,25 @@
|
|
|
23
23
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
|
|
24
24
|
"@eslint/js": "^8.53.0",
|
|
25
25
|
"@foray1010/common-presets-utils": "^8.0.0",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
27
|
-
"@typescript-eslint/parser": "^7.0.0",
|
|
28
26
|
"confusing-browser-globals": "^1.0.11",
|
|
29
|
-
"eslint-config-prettier": "^9.
|
|
27
|
+
"eslint-config-prettier": "^9.1.0",
|
|
30
28
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
31
|
-
"eslint-plugin-compat": "^
|
|
29
|
+
"eslint-plugin-compat": "^6.0.0",
|
|
32
30
|
"eslint-plugin-deprecation": "^3.0.0",
|
|
33
31
|
"eslint-plugin-functional": "^6.0.0",
|
|
34
|
-
"eslint-plugin-import": "^
|
|
35
|
-
"eslint-plugin-jest": "^28.
|
|
36
|
-
"eslint-plugin-jest-dom": "^5.
|
|
32
|
+
"eslint-plugin-import-x": "^3.0.1",
|
|
33
|
+
"eslint-plugin-jest": "^28.6.0",
|
|
34
|
+
"eslint-plugin-jest-dom": "^5.4.0",
|
|
37
35
|
"eslint-plugin-n": "^17.0.0",
|
|
38
|
-
"eslint-plugin-prettier": "^5.
|
|
39
|
-
"eslint-plugin-react": "^7.
|
|
36
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
37
|
+
"eslint-plugin-react": "^7.35.0",
|
|
40
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
41
|
-
"eslint-plugin-regexp": "^2.
|
|
39
|
+
"eslint-plugin-regexp": "^2.6.0",
|
|
42
40
|
"eslint-plugin-simple-import-sort": "^12.0.0",
|
|
43
41
|
"eslint-plugin-testing-library": "^6.1.2",
|
|
44
|
-
"eslint-plugin-unicorn": "^
|
|
45
|
-
"globals": "^15.4.0"
|
|
42
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
43
|
+
"globals": "^15.4.0",
|
|
44
|
+
"typescript-eslint": "^7.16.1"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@types/confusing-browser-globals": "1.0.3",
|
|
@@ -69,5 +68,5 @@
|
|
|
69
68
|
"publishConfig": {
|
|
70
69
|
"access": "public"
|
|
71
70
|
},
|
|
72
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7901467ba1addb02e74bd1da0a3bece07cffd22b"
|
|
73
72
|
}
|