@w5s/eslint-config 7.1.1 → 7.2.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": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -38,29 +38,30 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@e18e/eslint-plugin": "~0.8.0",
41
- "@eslint-react/eslint-plugin": "~5.24.0",
41
+ "@eslint-react/eslint-plugin": "~5.30.0",
42
42
  "@eslint/js": "~10.0.0",
43
43
  "@eslint/markdown": "~8.0.0",
44
44
  "@next/eslint-plugin-next": "~16.4.0",
45
45
  "@stylistic/eslint-plugin": "~5.10.0",
46
- "@typescript-eslint/eslint-plugin": "~8.71.0",
46
+ "@typescript-eslint/eslint-plugin": "~8.73.0",
47
47
  "@typescript-eslint/parser": "^8.65.0",
48
48
  "@vitest/eslint-plugin": "~1.6.20",
49
- "@w5s/dev": "^7.0.0",
50
- "@w5s/eslint-config-ignore": "^1.34.0",
51
- "@w5s/prettier-config": "^3.29.1",
49
+ "@w5s/dev": "^7.1.0",
50
+ "@w5s/eslint-config-ignore": "^1.34.1",
51
+ "@w5s/prettier-config": "^3.29.2",
52
52
  "eslint-merge-processors": "^2.0.0",
53
53
  "eslint-plugin-github-actions-2": "~2.0.0",
54
54
  "eslint-plugin-import": "~2.32.0",
55
- "eslint-plugin-jsdoc": "~65.2.0",
55
+ "eslint-plugin-jsdoc": "~65.5.0",
56
56
  "eslint-plugin-json-schema-validator-2": "~7.0.11",
57
57
  "eslint-plugin-jsonc": "~3.4.0",
58
- "eslint-plugin-n": "~18.4.0",
59
- "eslint-plugin-perfectionist": "~5.12.0",
58
+ "eslint-plugin-n": "~18.5.0",
59
+ "eslint-plugin-perfectionist": "~5.14.0",
60
+ "eslint-plugin-regexp": "~3.3.3",
60
61
  "eslint-plugin-toml": "~1.5.0",
61
- "eslint-plugin-unicorn": "~77.0.0",
62
+ "eslint-plugin-unicorn": "~80.0.0",
62
63
  "eslint-plugin-unused-imports": "~4.4.1",
63
- "eslint-plugin-yml": "~3.9.0",
64
+ "eslint-plugin-yml": "~3.10.0",
64
65
  "globals": "^17.0.0",
65
66
  "jsonc-eslint-parser": "^3.0.0",
66
67
  "parse-gitignore": "^2.0.0",
@@ -88,5 +89,5 @@
88
89
  "publishConfig": {
89
90
  "access": "public"
90
91
  },
91
- "gitHead": "d39c8e42e2e9cb34d05ea9e23c757383dd30795a"
92
+ "gitHead": "8c839f967fbc4477af3e767c4ecfa2d8a693eda0"
92
93
  }
@@ -1,13 +1,16 @@
1
1
  import { interopDefault, Project } from '@w5s/dev';
2
2
  import { mergeProcessors, processorPassThrough } from 'eslint-merge-processors';
3
+ import * as yamlParser from 'yaml-eslint-parser';
3
4
 
4
5
  import type { RuleOptions } from '../typegen/markdown.js';
6
+ import type { RuleOptions as SchemaRuleOptions } from '../typegen/schema.js';
5
7
 
6
8
  import { sourceGlob } from '../glob.js';
7
9
  import { defaultPluginOptions } from '../internal/defaultOptions.js';
8
10
  import { withDefaultFiles } from '../internal/withDefaultFiles.js';
11
+ import { withSchema } from '../internal/withSchema.js';
9
12
  import { looseRules } from '../rules/looseRules.js';
10
- import { type Config, type PluginOptionsBase } from '../type.js';
13
+ import { type Config, type PluginOptionsBase, type PluginOptionsSchema } from '../type.js';
11
14
 
12
15
  const defaultFiles = [Project.glob({ fileExtensions: [Project.queryExtensions(['markdown'])], nested: true })];
13
16
 
@@ -21,34 +24,67 @@ export async function markdown(options: markdown.Options = {}) {
21
24
  languageOptions,
22
25
  namespace,
23
26
  recommended,
24
- rules = {},
27
+ rules: allRules = {},
25
28
  stylistic,
26
29
  } = defaultPluginOptions(options);
30
+ // Schema rules target the virtual frontmatter file, not the markdown file
31
+ const { rules, schemaRules } = splitSchemaRules(allRules);
27
32
 
28
33
  const resolvedFiles = withDefaultFiles(files, defaultFiles);
34
+ const schemaConfig = await withSchema(options.schema);
35
+ const resolvedLanguageOptions = { frontmatter: 'yaml' as 'toml' | 'yaml' | undefined, ...languageOptions };
36
+ // The schema validator only extracts YAML frontmatter
37
+ const frontmatterSchemaEnabled =
38
+ Object.keys(schemaConfig.rules).length > 0 && resolvedLanguageOptions.frontmatter === 'yaml';
39
+
29
40
  return [
30
41
  {
31
42
  name: `${namespace}/markdown/setup`,
32
43
  plugins: {
33
44
  markdown: markdownPlugin,
45
+ ...schemaConfig.plugins,
34
46
  },
35
47
  },
36
48
  {
37
49
  files: resolvedFiles,
38
50
  language,
39
- languageOptions: {
40
- frontmatter: 'yaml',
41
- ...languageOptions,
42
- },
51
+ languageOptions: resolvedLanguageOptions,
43
52
  name: `${namespace}/markdown/rules`,
44
53
 
45
- processor: mergeProcessors([markdownPlugin.processors.markdown, processorPassThrough]),
54
+ processor: mergeProcessors([
55
+ markdownPlugin.processors.markdown,
56
+ ...(frontmatterSchemaEnabled ? [schemaConfig.plugins.schema.processors.frontmatter] : []),
57
+ processorPassThrough,
58
+ ]),
46
59
  rules: {
47
60
  ...(recommended ? markdownPlugin.configs.recommended.at(0)?.rules : {}),
61
+ ...(recommended
62
+ ? {
63
+ 'markdown/no-multiple-h1': ['error', { frontmatterTitle: '' }], // Enforce a single H1, ignoring the frontmatter title
64
+ }
65
+ : {}),
48
66
  ...(stylistic.enabled ? {} : {}),
49
67
  ...rules,
50
68
  },
51
69
  },
70
+ {
71
+ files: resolvedFiles.map((f) => `${f}/**/*.frontmatter.yaml`),
72
+ languageOptions: {
73
+ parser: yamlParser,
74
+ },
75
+ name: `${namespace}/markdown/frontmatter`,
76
+ rules: frontmatterSchemaEnabled
77
+ ? {
78
+ 'no-irregular-whitespace': 'off',
79
+ 'no-unused-vars': 'off',
80
+ 'spaced-comment': 'off',
81
+ 'style/eol-last': 'off',
82
+ 'style/no-multiple-empty-lines': 'off',
83
+ ...schemaConfig.rules,
84
+ ...schemaRules,
85
+ }
86
+ : {},
87
+ },
52
88
  {
53
89
  files: resolvedFiles.map((f) => `${f}/${sourceGlob}`),
54
90
  languageOptions: {
@@ -59,7 +95,6 @@ export async function markdown(options: markdown.Options = {}) {
59
95
  },
60
96
  name: `${namespace}/markdown/embed-code`,
61
97
  rules: {
62
- 'markdown/no-multiple-h1': ['error', { frontmatterTitle: '' }], // Enforce a single H1, ignoring the frontmatter title
63
98
  ...looseRules(),
64
99
  'no-alert': 'off',
65
100
  'no-console': 'off',
@@ -82,11 +117,22 @@ export async function markdown(options: markdown.Options = {}) {
82
117
  'unused-imports/no-unused-vars': 'off',
83
118
  },
84
119
  },
85
- ] as [Config, Config, Config] satisfies Array<Config>;
120
+ ] as [Config, Config, Config, Config] satisfies Array<Config>;
121
+ }
122
+
123
+ function splitSchemaRules<R extends object>(allRules: R) {
124
+ const rules: Record<string, unknown> = {};
125
+ const schemaRules: Record<string, unknown> = {};
126
+
127
+ for (const [name, value] of Object.entries(allRules)) {
128
+ (name.startsWith('schema/') ? schemaRules : rules)[name] = value;
129
+ }
130
+
131
+ return { rules: rules as Partial<R>, schemaRules: schemaRules as Partial<R> };
86
132
  }
87
133
 
88
134
  export namespace markdown {
89
- export interface Options extends PluginOptionsBase<Rules> {
135
+ export interface Options extends PluginOptionsBase<Rules>, PluginOptionsSchema {
90
136
  /**
91
137
  * Default to 'markdown/gfm' (Github Flavored Markdown)
92
138
  */
@@ -102,5 +148,5 @@ export namespace markdown {
102
148
  };
103
149
  }
104
150
 
105
- export type Rules = RuleOptions;
151
+ export type Rules = RuleOptions & SchemaRuleOptions;
106
152
  }
@@ -0,0 +1,43 @@
1
+ import { interopDefault } from '@w5s/dev';
2
+
3
+ import type { RuleOptions } from '../typegen/regex.js';
4
+
5
+ import { sourceGlob } from '../glob.js';
6
+ import { defaultPluginOptions } from '../internal/defaultOptions.js';
7
+ import { withDefaultFiles } from '../internal/withDefaultFiles.js';
8
+ import { type Config, type PluginOptionsBase } from '../type.js';
9
+
10
+ const defaultFiles = [sourceGlob];
11
+
12
+ export async function regexp(options: regexp.Options = {}) {
13
+ const regexPlugin = await interopDefault(import('eslint-plugin-regexp'));
14
+ const { files, namespace, recommended, rules = {}, stylistic } = defaultPluginOptions(options);
15
+
16
+ return [
17
+ {
18
+ name: `${namespace}/regexp/setup`,
19
+ plugins: {
20
+ regex: regexPlugin,
21
+ },
22
+ },
23
+ {
24
+ files: withDefaultFiles(files, defaultFiles),
25
+ name: `${namespace}/regexp/rules`,
26
+ rules: {
27
+ ...(recommended ? regexPlugin.configs?.['flat/recommended']?.rules ?? {} : {}),
28
+ ...(stylistic
29
+ ? {
30
+ // TODO: remove stylistic rules from flat/recommended and put it here
31
+ }
32
+ : {}),
33
+ ...rules,
34
+ },
35
+ },
36
+ ] as [Config, Config] satisfies Array<Config>;
37
+ }
38
+
39
+ export namespace regexp {
40
+ export interface Options extends PluginOptionsBase<Rules> {}
41
+
42
+ export type Rules = RuleOptions;
43
+ }
package/src/config.ts CHANGED
@@ -11,6 +11,7 @@ export * from './config/next.js';
11
11
  export * from './config/node.js';
12
12
  export * from './config/perfectionist.js';
13
13
  export * from './config/react.js';
14
+ export * from './config/regexp.js';
14
15
  export * from './config/stylistic.js';
15
16
  export * from './config/test.js';
16
17
  export * from './config/toml.js';
@@ -31,6 +31,7 @@ export interface DefineConfigOptions extends config.ignores.Options {
31
31
  'node'?: boolean | config.node.Options | undefined;
32
32
  'perfectionist'?: boolean | config.perfectionist.Options | undefined;
33
33
  'react'?: boolean | config.react.Options | undefined;
34
+ 'regexp'?: boolean | config.regexp.Options | undefined;
34
35
  'stylistic'?: boolean | config.stylistic.Options | undefined;
35
36
  'test'?: boolean | config.test.Options | undefined;
36
37
  'toml'?: boolean | config.toml.Options | undefined;
@@ -89,6 +90,7 @@ export async function defineConfig(options: DefineConfigOptions = {}): Promise<A
89
90
  ...includeEnabled(config.node, toOption(plugins.node)),
90
91
  ...includeEnabled(config.next, toOption(plugins.next, false)),
91
92
  ...includeEnabled(config.react, toOption(plugins.react)),
93
+ ...includeEnabled(config.regexp, toOption(plugins.regexp, false)),
92
94
  ...includeEnabled(config.unicorn, toOption(plugins.unicorn)),
93
95
  ...includeEnabled(config.test, toOption(plugins.test)),
94
96
  // Stylistic
@@ -93,7 +93,7 @@ export interface RuleOptions {
93
93
  * Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies`
94
94
  * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/imports-as-dependencies.md#repos-sticky-header
95
95
  */
96
- 'jsdoc/imports-as-dependencies'?: Linter.RuleEntry<[]>
96
+ 'jsdoc/imports-as-dependencies'?: Linter.RuleEntry<JsdocImportsAsDependencies>
97
97
  /**
98
98
  * This rule reports doc comments that only restate their attached name.
99
99
  * @see https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/informative-docs.md#repos-sticky-header
@@ -585,6 +585,17 @@ type JsdocImplementsOnClasses = []|[{
585
585
  comment?: string
586
586
  context?: string
587
587
  })[]
588
+
589
+ fix?: ("remove" | "type")
590
+ }]
591
+ // ----- jsdoc/imports-as-dependencies -----
592
+ type JsdocImportsAsDependencies = []|[{
593
+
594
+ dependencies?: boolean
595
+
596
+ devDependencies?: boolean
597
+
598
+ peerDependencies?: boolean
588
599
  }]
589
600
  // ----- jsdoc/informative-docs -----
590
601
  type JsdocInformativeDocs = []|[{
@@ -753,6 +764,8 @@ type JsdocNoUnnecessaryTypeAssertion = []|[{
753
764
 
754
765
  enableFixer?: boolean
755
766
 
767
+ fixTypeChangingCasts?: boolean
768
+
756
769
  preferConstToLiteralTuples?: boolean
757
770
 
758
771
  treatAnyAsRedundant?: boolean
@@ -806,6 +819,13 @@ type JsdocRequireDescription = []|[{
806
819
  descriptionStyle?: ("body" | "tag" | "any")
807
820
 
808
821
  exemptedBy?: string[]
822
+
823
+ publicOnly?: (boolean | {
824
+ ancestorsOnly?: boolean
825
+ cjs?: boolean
826
+ esm?: boolean
827
+ window?: boolean
828
+ })
809
829
  }]
810
830
  // ----- jsdoc/require-description-complete-sentence -----
811
831
  type JsdocRequireDescriptionCompleteSentence = []|[{
@@ -946,6 +966,8 @@ type JsdocRequireParam = []|[{
946
966
  unnamedRootBase?: string[]
947
967
 
948
968
  useDefaultObjectProperties?: boolean
969
+
970
+ useObjectTypeForDestructuredRoots?: boolean
949
971
  }]
950
972
  // ----- jsdoc/require-param-description -----
951
973
  type JsdocRequireParamDescription = []|[{
@@ -957,6 +979,13 @@ type JsdocRequireParamDescription = []|[{
957
979
 
958
980
  defaultDestructuredRootDescription?: string
959
981
 
982
+ publicOnly?: (boolean | {
983
+ ancestorsOnly?: boolean
984
+ cjs?: boolean
985
+ esm?: boolean
986
+ window?: boolean
987
+ })
988
+
960
989
  setDefaultDestructuredRootDescription?: boolean
961
990
  }]
962
991
  // ----- jsdoc/require-param-name -----
@@ -1035,6 +1064,13 @@ type JsdocRequireReturnsDescription = []|[{
1035
1064
  comment?: string
1036
1065
  context?: string
1037
1066
  })[]
1067
+
1068
+ publicOnly?: (boolean | {
1069
+ ancestorsOnly?: boolean
1070
+ cjs?: boolean
1071
+ esm?: boolean
1072
+ window?: boolean
1073
+ })
1038
1074
  }]
1039
1075
  // ----- jsdoc/require-returns-type -----
1040
1076
  type JsdocRequireReturnsType = []|[{