@w5s/eslint-config 3.14.0 → 3.17.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/eslint-config",
3
- "version": "3.14.0",
3
+ "version": "3.17.0",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@e18e/eslint-plugin": "^0.5.0",
40
- "@eslint-react/eslint-plugin": "5.11.2",
40
+ "@eslint-react/eslint-plugin": "5.17.1",
41
41
  "@eslint/js": "^10.0.0",
42
42
  "@eslint/markdown": "^8.0.0",
43
43
  "@next/eslint-plugin-next": "^16.0.0",
@@ -45,17 +45,18 @@
45
45
  "@typescript-eslint/eslint-plugin": "^8.0.0",
46
46
  "@typescript-eslint/parser": "^8.0.0",
47
47
  "@vitest/eslint-plugin": "~1.6.20",
48
- "@w5s/dev": "^3.5.0",
49
- "@w5s/eslint-config-ignore": "^1.4.0",
50
- "@w5s/prettier-config": "^3.1.18",
48
+ "@w5s/dev": "^3.8.0",
49
+ "@w5s/eslint-config-ignore": "^1.7.0",
50
+ "@w5s/prettier-config": "^3.2.0",
51
51
  "eslint-merge-processors": "^2.0.0",
52
52
  "eslint-plugin-import": "~2.32.0",
53
53
  "eslint-plugin-jsdoc": "~63.0.0",
54
- "eslint-plugin-jsonc": "~3.2.0",
54
+ "eslint-plugin-jsonc": "~3.3.0",
55
55
  "eslint-plugin-n": "~18.2.0",
56
- "eslint-plugin-perfectionist": "~5.9.1",
57
- "eslint-plugin-unicorn": "~69.0.0",
58
- "eslint-plugin-yml": "~3.5.0",
56
+ "eslint-plugin-perfectionist": "~5.10.0",
57
+ "eslint-plugin-unicorn": "~71.1.0",
58
+ "eslint-plugin-unused-imports": "~4.4.1",
59
+ "eslint-plugin-yml": "~3.6.0",
59
60
  "globals": "^17.0.0",
60
61
  "jsonc-eslint-parser": "^3.0.0",
61
62
  "parse-gitignore": "^2.0.0",
@@ -63,12 +64,16 @@
63
64
  },
64
65
  "peerDependencies": {
65
66
  "eslint": "9.x || 10.x",
67
+ "eslint-plugin-jsx-a11y": ">=6.10.2",
66
68
  "typescript": "4.x || 5.x || 6.x"
67
69
  },
68
70
  "peerDependenciesMeta": {
69
71
  "eslint": {
70
72
  "optional": true
71
73
  },
74
+ "eslint-plugin-jsx-a11y": {
75
+ "optional": true
76
+ },
72
77
  "typescript": {
73
78
  "optional": true
74
79
  }
@@ -80,5 +85,5 @@
80
85
  "access": "public"
81
86
  },
82
87
  "sideEffect": false,
83
- "gitHead": "2d215d8f8c7c57653b9f0ef5674ffc2e7beeea5c"
88
+ "gitHead": "8a983003d499b2d34ff7ce0bd9e4294549f7642b"
84
89
  }
@@ -0,0 +1,51 @@
1
+ import { interopDefault } from '@w5s/dev';
2
+
3
+ import type { RuleOptions } from '../typegen/jsx-a11y.js';
4
+
5
+ import { jsxSourceGlob } from '../glob.js';
6
+ import { withDefaultFiles } from '../internal/withDefaultFiles.js';
7
+ import { type Config, type PluginOptionsBase } from '../type.js';
8
+
9
+ const defaultFiles = [jsxSourceGlob];
10
+
11
+ export async function jsx(options: jsx.Options = {}) {
12
+ const { files, jsxA11y = false, recommended = true, rules = {} } = options;
13
+ const [jsxA11yPlugin] = await Promise.all([
14
+ jsxA11y ? interopDefault(import('eslint-plugin-jsx-a11y')) : undefined,
15
+ ] as const);
16
+ return [
17
+ {
18
+ languageOptions: {
19
+ parserOptions: {
20
+ ecmaFeatures: {
21
+ jsx: true,
22
+ },
23
+ },
24
+ sourceType: 'module',
25
+ },
26
+ name: 'w5s/jsx/setup',
27
+ plugins: {
28
+ ...(jsxA11yPlugin ? { 'jsx-a11y': jsxA11yPlugin } : {}),
29
+ },
30
+ },
31
+ {
32
+ files: withDefaultFiles(files, defaultFiles),
33
+ name: 'w5s/jsx/rules',
34
+ rules: {
35
+ ...(recommended && jsxA11yPlugin != null ? jsxA11yPlugin.configs['recommended'].rules : {}),
36
+ ...rules,
37
+ },
38
+ },
39
+ ] as [Config, Config] satisfies Array<Config>;
40
+ }
41
+
42
+ export namespace jsx {
43
+ export interface Options extends Omit<PluginOptionsBase<Rules>, 'stylistic'> {
44
+ /**
45
+ * Enable jsx-a11y plugin. Defaults to false.
46
+ */
47
+ jsxA11y?: boolean;
48
+ }
49
+
50
+ export type Rules = RuleOptions;
51
+ }
@@ -6,7 +6,7 @@ import type { RuleOptions } from '../typegen/markdown.js';
6
6
  import { withDefaultFiles } from '../internal/withDefaultFiles.js';
7
7
  import { type Config, type PluginOptionsBase, StylisticConfig } from '../type.js';
8
8
 
9
- const defaultFiles = [`**/${Project.extensionsToGlob(Project.queryExtensions(['markdown']))}`, '**/CHANGELOG.md', '**/CODE_OF_CONDUCT.md'];
9
+ const defaultFiles = [`**/${Project.extensionsToGlob(Project.queryExtensions(['markdown']))}`];
10
10
 
11
11
  export async function markdown(options: markdown.Options = {}) {
12
12
  const [markdownPlugin] = await Promise.all([interopDefault(import('@eslint/markdown'))] as const);
@@ -2,6 +2,7 @@ import { interopDefault } from '@w5s/dev';
2
2
 
3
3
  import type { RuleOptions } from '../typegen/react.js';
4
4
 
5
+ import { ESLintConfig } from '../../../dev/dist/index.cjs';
5
6
  import { sourceGlob } from '../glob.js';
6
7
  import { withDefaultFiles } from '../internal/withDefaultFiles.js';
7
8
  import { type Config, type PluginOptionsBase } from '../type.js';
@@ -12,7 +13,7 @@ export async function react(options: react.Options = {}) {
12
13
  const [reactPlugin] = await Promise.all([
13
14
  interopDefault(import('@eslint-react/eslint-plugin')),
14
15
  ] as const);
15
- const { files, recommended, rules = {} } = options;
16
+ const { files, recommended = true, rules = {} } = options;
16
17
  return [
17
18
  {
18
19
  name: 'w5s/react/setup',
@@ -32,7 +33,8 @@ export async function react(options: react.Options = {}) {
32
33
  },
33
34
  name: 'w5s/react/rules',
34
35
  rules: {
35
- ...(recommended ? reactPlugin.configs['recommended'].rules : {}),
36
+ // eslint-disable-next-line ts/no-non-null-assertion
37
+ ...(recommended ? ESLintConfig.renameRules(reactPlugin.configs['recommended'].rules!, { '@eslint-react': 'react' }) : {}),
36
38
  ...rules,
37
39
  },
38
40
  },
@@ -0,0 +1,51 @@
1
+ import { interopDefault } from '@w5s/dev';
2
+
3
+ import type { RuleOptions } from '../typegen/unused-imports.js';
4
+
5
+ import { sourceGlob } from '../glob.js';
6
+ import { type Config, type PluginOptionsBase } from '../type.js';
7
+
8
+ export async function unusedImports(options: unusedImports.Options = {}) {
9
+ const [unusedImportPlugin] = await Promise.all([
10
+ interopDefault(import('eslint-plugin-unused-imports')),
11
+ ] as const);
12
+ const { files = [sourceGlob], recommended = true, rules = {} } = options;
13
+
14
+ return [
15
+ {
16
+ name: 'w5s/unused-imports/setup',
17
+ plugins: {
18
+ 'unused-imports': unusedImportPlugin,
19
+ },
20
+ },
21
+ {
22
+ files,
23
+ name: 'w5s/unused-imports/rules',
24
+ rules: {
25
+ ...(recommended
26
+ ? {
27
+ 'no-unused-vars': 'off', // disable the base rule as it can report incorrect errors
28
+ 'ts/no-unused-vars': 'off', // disable the base rule as it can report incorrect errors
29
+ 'unused-imports/no-unused-imports': 'error',
30
+ 'unused-imports/no-unused-vars': [
31
+ 'error',
32
+ {
33
+ args: 'after-used',
34
+ argsIgnorePattern: '^_',
35
+ vars: 'all',
36
+ varsIgnorePattern: '^_',
37
+ },
38
+ ],
39
+ }
40
+ : {}),
41
+ ...rules,
42
+ },
43
+ },
44
+ ] as [Config, Config] satisfies Array<Config>;
45
+ }
46
+
47
+ export namespace unusedImports {
48
+ export interface Options extends PluginOptionsBase<Rules> {}
49
+
50
+ export type Rules = RuleOptions;
51
+ }
package/src/config.ts CHANGED
@@ -4,6 +4,7 @@ export * from './config/ignores.js';
4
4
  export * from './config/imports.js';
5
5
  export * from './config/jsdoc.js';
6
6
  export * from './config/jsonc.js';
7
+ export * from './config/jsx.js';
7
8
  export * from './config/markdown.js';
8
9
  export * from './config/next.js';
9
10
  export * from './config/node.js';
@@ -13,4 +14,5 @@ export * from './config/stylistic.js';
13
14
  export * from './config/test.js';
14
15
  export * from './config/ts.js';
15
16
  export * from './config/unicorn.js';
17
+ export * from './config/unused-imports.js';
16
18
  export * from './config/yml.js';
@@ -11,6 +11,7 @@ import {
11
11
  imports,
12
12
  jsdoc,
13
13
  jsonc,
14
+ jsx,
14
15
  markdown,
15
16
  next,
16
17
  node,
@@ -20,6 +21,7 @@ import {
20
21
  test,
21
22
  ts,
22
23
  unicorn,
24
+ unusedImports,
23
25
  yml,
24
26
  } from './config.js';
25
27
 
@@ -28,21 +30,23 @@ export interface DefineConfigOptions extends ignores.Options {
28
30
  * Plugins configuration
29
31
  */
30
32
  plugins?: {
31
- e18e?: boolean | e18e.Options;
32
- es?: boolean | es.Options;
33
- import?: boolean | imports.Options;
34
- jsdoc?: boolean | jsdoc.Options;
35
- jsonc?: boolean | jsonc.Options;
36
- markdown?: boolean | markdown.Options;
37
- next?: boolean | next.Options;
38
- node?: boolean | node.Options;
39
- perfectionist?: boolean | perfectionist.Options;
40
- react?: boolean | react.Options;
41
- stylistic?: boolean | stylistic.Options;
42
- test?: boolean | test.Options;
43
- ts?: boolean | ts.Options;
44
- unicorn?: boolean | unicorn.Options;
45
- yml?: boolean | yml.Options;
33
+ 'e18e'?: boolean | e18e.Options;
34
+ 'es'?: boolean | es.Options;
35
+ 'import'?: boolean | imports.Options;
36
+ 'jsdoc'?: boolean | jsdoc.Options;
37
+ 'jsonc'?: boolean | jsonc.Options;
38
+ 'jsx'?: boolean | jsx.Options;
39
+ 'markdown'?: boolean | markdown.Options;
40
+ 'next'?: boolean | next.Options;
41
+ 'node'?: boolean | node.Options;
42
+ 'perfectionist'?: boolean | perfectionist.Options;
43
+ 'react'?: boolean | react.Options;
44
+ 'stylistic'?: boolean | stylistic.Options;
45
+ 'test'?: boolean | test.Options;
46
+ 'ts'?: boolean | ts.Options;
47
+ 'unicorn'?: boolean | unicorn.Options;
48
+ 'unused-imports'?: boolean | unusedImports.Options;
49
+ 'yml'?: boolean | yml.Options;
46
50
  };
47
51
 
48
52
  /**
@@ -77,6 +81,7 @@ export async function defineConfig(options: DefineConfigOptions = {}) {
77
81
  ...includeEnabled(ignores, toOption(options)),
78
82
  ...includeEnabled(jsonc, toOption(plugins.jsonc)),
79
83
  ...includeEnabled(jsdoc, toOption(plugins.jsdoc)),
84
+ ...includeEnabled(jsx, toOption(plugins.jsx)),
80
85
  ...includeEnabled(react, toOption(plugins.react)),
81
86
  ...includeEnabled(stylistic, toOption(plugins.stylistic)),
82
87
  ...includeEnabled(imports, toOption(plugins.import)),
@@ -87,6 +92,8 @@ export async function defineConfig(options: DefineConfigOptions = {}) {
87
92
  ...includeEnabled(unicorn, toOption(plugins.unicorn)),
88
93
  ...includeEnabled(yml, toOption(plugins.yml)),
89
94
  ...includeEnabled(test, toOption(plugins.test)),
95
+ // Unused imports plugin is a special case because it needs to be included in the config even if it's disabled, to ensure that the rules are applied correctly.
96
+ ...includeEnabled(unusedImports, toOption(plugins['unused-imports'])),
90
97
  ...(rules ? [{ rules }] : []),
91
98
  );
92
99
  }
package/src/glob.ts CHANGED
@@ -4,6 +4,8 @@ export const sourceGlob = `**/${Project.extensionsToGlob(Project.sourceExtension
4
4
 
5
5
  export const esSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['javascript', 'javascriptreact']))}`;
6
6
 
7
+ export const jsxSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['javascriptreact', 'typescriptreact']))}`;
8
+
7
9
  export const jsonSourceGlob = `**/${Project.extensionsToGlob(['.json', '.json5', '.jsonc'])}`;
8
10
 
9
11
  export const tsSourceGlob = `**/${Project.extensionsToGlob(Project.queryExtensions(['typescript', 'typescriptreact']))}`;
@@ -426,11 +426,13 @@ type JsoncSortArrayValues = [{
426
426
  type?: ("asc" | "desc")
427
427
  caseSensitive?: boolean
428
428
  natural?: boolean
429
+ key?: string
429
430
  }
430
431
  })[] | {
431
432
  type?: ("asc" | "desc")
432
433
  caseSensitive?: boolean
433
434
  natural?: boolean
435
+ key?: string
434
436
  })
435
437
  minValues?: number
436
438
  }, ...({
@@ -441,11 +443,13 @@ type JsoncSortArrayValues = [{
441
443
  type?: ("asc" | "desc")
442
444
  caseSensitive?: boolean
443
445
  natural?: boolean
446
+ key?: string
444
447
  }
445
448
  })[] | {
446
449
  type?: ("asc" | "desc")
447
450
  caseSensitive?: boolean
448
451
  natural?: boolean
452
+ key?: string
449
453
  })
450
454
  minValues?: number
451
455
  })[]]