@foray1010/eslint-config 12.2.3 → 12.3.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/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.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@12.2.4...@foray1010/eslint-config@12.3.0) (2024-07-21)
7
+
8
+ ### Features
9
+
10
+ - **eslint-config:** migrate eslint plugin from import to import-x ([ae44cee](https://github.com/foray1010/common-presets/commit/ae44ceefa797f0afbe690c337baf7ecd58420ea9))
11
+
12
+ ### Bug Fixes
13
+
14
+ - **deps:** update dependency eslint-plugin-compat to v6 ([e7676b2](https://github.com/foray1010/common-presets/commit/e7676b2b3506cb4d92e512d40f487e007f64bd30))
15
+
16
+ ## [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)
17
+
18
+ ### Bug Fixes
19
+
20
+ - **deps:** update dependency eslint-plugin-compat to v5 ([d9743af](https://github.com/foray1010/common-presets/commit/d9743af383e66d3365db4024cbf7c40572eb50d4))
21
+ - **deps:** update dependency eslint-plugin-unicorn to v54 ([33438db](https://github.com/foray1010/common-presets/commit/33438db1de6efc74a90510b5003e6464bcfd630f))
22
+
6
23
  ## [12.2.3](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@12.2.2...@foray1010/eslint-config@12.2.3) (2024-06-09)
7
24
 
8
25
  ### Bug Fixes
package/bases/base.mjs CHANGED
@@ -1,12 +1,14 @@
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 eslintPluginImport from 'eslint-plugin-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'
8
8
  import eslintPluginUnicorn from 'eslint-plugin-unicorn'
9
9
  import globals from 'globals'
10
+ // eslint-disable-next-line import-x/no-unresolved
11
+ import tseslint from 'typescript-eslint'
10
12
 
11
13
  import {
12
14
  testFileGlobs,
@@ -21,23 +23,21 @@ async function generateTypeScriptConfig() {
21
23
  // typescript plugins are depended on `typescript` package
22
24
  if (!hasDep('typescript')) return []
23
25
 
24
- /* eslint-disable import/no-unresolved */
25
- const eslintPluginTypescriptEslint = (
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 */
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
- ...eslintPluginTypescriptEslint.configs[
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,12 +263,12 @@ 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,
291
270
  globals: {
292
- // No es2022/es2023 preset yet
293
- ...globals.es2021,
271
+ ...globals.es2023,
294
272
  /* Not using `node` to explicitly import node.js only built-in modules, e.g.
295
273
  * import { Buffer } from 'node:buffer'
296
274
  * import process from 'node:process'
@@ -300,19 +278,13 @@ const baseConfig = [
300
278
  },
301
279
  plugins: {
302
280
  '@eslint-community/eslint-comments': eslintPluginEslintComments,
303
- import: eslintPluginImport,
304
- regexp: eslintPluginRegexp,
281
+ // @ts-expect-error Type is not compact with flat config
282
+ 'import-x': eslintPluginImportX,
305
283
  unicorn: eslintPluginUnicorn,
306
284
  },
307
285
  rules: {
308
286
  ...eslintPluginEslintComments.configs['recommended']?.rules,
309
- ...eslintPluginImport.configs['recommended']?.rules,
310
- ...(() => {
311
- const rules = eslintPluginRegexp.configs['recommended']?.rules
312
- return /** @type {import('eslint').Linter.RulesRecord} */ (
313
- /** @type {unknown} */ (rules)
314
- )
315
- })(),
287
+ ...eslintPluginImportX.configs['recommended']?.rules,
316
288
  ...Object.fromEntries(
317
289
  Object.entries(
318
290
  eslintPluginUnicorn.configs['flat/recommended']?.rules ?? {},
@@ -334,9 +306,9 @@ const baseConfig = [
334
306
  // always use named function for easier to debug via stack trace
335
307
  'func-names': ['error', 'as-needed'],
336
308
  // this rule doesn't support commonjs, some dependencies are using commonjs
337
- 'import/default': 'off',
309
+ 'import-x/default': 'off',
338
310
  // enforce extensions for both cjs and esm
339
- 'import/extensions': [
311
+ 'import-x/extensions': [
340
312
  'error',
341
313
  // https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_mandatory_file_extensions
342
314
  'always',
@@ -351,12 +323,12 @@ const baseConfig = [
351
323
  },
352
324
  ],
353
325
  // make sure import statements above the others
354
- 'import/first': 'error',
326
+ 'import-x/first': 'error',
355
327
  // separate import statements from the others
356
- 'import/newline-after-import': 'error',
328
+ 'import-x/newline-after-import': 'error',
357
329
  // avoid anonymous function or class for easier to debug via stack trace
358
330
  // for other types, enforcing named data can improve autocomplete when importing
359
- 'import/no-anonymous-default-export': [
331
+ 'import-x/no-anonymous-default-export': [
360
332
  'error',
361
333
  {
362
334
  allowArray: false,
@@ -369,7 +341,7 @@ const baseConfig = [
369
341
  },
370
342
  ],
371
343
  // no circular dependency
372
- 'import/no-cycle': [
344
+ 'import-x/no-cycle': [
373
345
  'error',
374
346
  {
375
347
  // speed up linting time
@@ -377,7 +349,7 @@ const baseConfig = [
377
349
  },
378
350
  ],
379
351
  // do not allow import packages that are not listed in dependencies or peerDependencies
380
- 'import/no-extraneous-dependencies': [
352
+ 'import-x/no-extraneous-dependencies': [
381
353
  'error',
382
354
  {
383
355
  devDependencies: [
@@ -388,9 +360,9 @@ const baseConfig = [
388
360
  },
389
361
  ],
390
362
  // forbid a module from importing itself
391
- 'import/no-self-import': 'error',
363
+ 'import-x/no-self-import': 'error',
392
364
  // use the shortest path in import statement, but allow /index because it will be standard to omit index as default file in directory
393
- 'import/no-useless-path-segments': [
365
+ 'import-x/no-useless-path-segments': [
394
366
  'error',
395
367
  {
396
368
  commonjs: true,
@@ -398,9 +370,10 @@ const baseConfig = [
398
370
  },
399
371
  ],
400
372
  // turn off these rules as they do not support flat config: https://github.com/import-js/eslint-plugin-import/issues/2556
401
- 'import/namespace': 'off',
402
- 'import/no-named-as-default': 'off',
403
- 'import/no-named-as-default-member': 'off',
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',
404
377
  // prefer explicitly convert type for readability
405
378
  'no-implicit-coercion': 'error',
406
379
  // make sure private class members are in-use
@@ -448,15 +421,12 @@ const baseConfig = [
448
421
  },
449
422
  {
450
423
  files: testFileGlobs,
451
- languageOptions: {
452
- globals: globals.jest,
453
- },
454
- plugins: {
455
- jest: eslintPluginJest,
456
- },
424
+ ...eslintPluginJest.configs['flat/recommended'],
425
+ ...eslintPluginJest.configs['flat/style'],
426
+ },
427
+ {
428
+ files: testFileGlobs,
457
429
  rules: {
458
- ...eslintPluginJest.configs['recommended']?.rules,
459
- ...eslintPluginJest.configs['style']?.rules,
460
430
  // make sure lifecycle hooks on the top for readability
461
431
  'jest/prefer-hooks-on-top': 'error',
462
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 eslintPluginImport from 'eslint-plugin-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
- plugins: {
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
- import: eslintPluginImport,
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
  ]
@@ -1,19 +1,12 @@
1
- import eslintConfigPrettier from 'eslint-config-prettier'
2
- import eslintPluginPrettier from 'eslint-plugin-prettier'
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
- // should be placed at the end to override other configs
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.2.3",
4
+ "version": "12.3.0",
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.0.0",
27
+ "eslint-config-prettier": "^9.1.0",
30
28
  "eslint-import-resolver-typescript": "^3.6.1",
31
- "eslint-plugin-compat": "^4.2.0",
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": "^2.29.0",
35
- "eslint-plugin-jest": "^28.0.0",
36
- "eslint-plugin-jest-dom": "^5.1.0",
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.0.1",
39
- "eslint-plugin-react": "^7.33.2",
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.1.1",
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": "^53.0.0",
45
- "globals": "^15.0.0"
42
+ "eslint-plugin-unicorn": "^54.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": "174cbacf95dbe42da4b06de9a009096c2eb7a196"
71
+ "gitHead": "e751b4ba48732b04545e8f4b99e682cf5ba74dab"
73
72
  }