@kazupon/eslint-config 0.17.0 → 0.18.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/README.md CHANGED
@@ -25,6 +25,7 @@ ESLint config for @kazupon
25
25
  - `jsonc`
26
26
  - `yml`
27
27
  - `toml`
28
+ - `markdown`
28
29
  - Support primitive eslint flat configuration
29
30
  - Support overrides for built-in configurations
30
31
  - `rules`
@@ -85,6 +86,8 @@ Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?it
85
86
 
86
87
  Add the following settings to your `.vscode/settings.json`:
87
88
 
89
+ <!-- eslint-skip -->
90
+
88
91
  ```jsonc
89
92
  {
90
93
  // Auto fix
@@ -94,12 +97,15 @@ Add the following settings to your `.vscode/settings.json`:
94
97
  // Enable eslint for supported languages
95
98
  "eslint.validate": [
96
99
  "javascript",
100
+ "javascriptreact",
97
101
  "typescript",
102
+ "typescriptreact",
98
103
  "vue",
99
104
  "svelte",
100
105
  "json",
101
106
  "jsonc",
102
107
  "json5",
108
+ "markdown",
103
109
  "yaml",
104
110
  "toml"
105
111
  ],
@@ -117,7 +123,7 @@ The following built-in preset configurations are supported:
117
123
  | `javascript` | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) | no (built-in) |
118
124
  | `comments` | [`@eslint-community/eslint-plugin-eslint-comments`](https://www.npmjs.com/package/@eslint-community/eslint-plugin-eslint-comments) | no (built-in) |
119
125
  | `typescript` | [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | yes |
120
- | `imports` | [`eslint-plugin-import-x`](https://www.npmjs.com/package/eslint-plugin-import-x), [`eslint-plugin-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) | yes |
126
+ | `imports` | [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import), [`eslint-plugin-unused-imports`](https://www.npmjs.com/package/eslint-plugin-unused-imports) | yes |
121
127
  | `jsdoc` | [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) | yes |
122
128
  | `regexp` | [`eslint-plugin-regexp`](https://www.npmjs.com/package/eslint-plugin-regexp) | yes |
123
129
  | `promise` | [`eslint-plugin-promise`](https://www.npmjs.com/package/eslint-plugin-promise) | yes |
@@ -130,6 +136,7 @@ The following built-in preset configurations are supported:
130
136
  | `jsonc` | [`eslint-plugin-jsonc`](https://www.npmjs.com/package/eslint-plugin-jsonc) | yes |
131
137
  | `yml` | [`eslint-plugin-yml`](https://www.npmjs.com/package/eslint-plugin-yml) | yes |
132
138
  | `toml` | [`eslint-plugin-toml`](https://www.npmjs.com/package/eslint-plugin-toml) | yes |
139
+ | `markdown` | [`@eslint/markdown`](https://www.npmjs.com/package/@eslint/markdown) | yes |
133
140
 
134
141
  You can use `import` syntax:
135
142
 
package/dist/config.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FlatConfigComposer } from 'eslint-flat-config-utils';
2
- import type { Linter } from 'eslint';
3
2
  import type { Awaitable } from '@kazupon/jts-utils/types';
3
+ import type { Linter } from 'eslint';
4
4
  /**
5
5
  * define eslint configurations
6
6
  * @param {Awaitable<Linter.Config | Linter.Config[]>[]} configs eslint flat configurations
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FlatConfigComposer } from 'eslint-flat-config-utils';
2
- import type { Linter } from 'eslint';
3
2
  import type { Awaitable } from '@kazupon/jts-utils/types';
3
+ import type { Linter } from 'eslint';
4
4
  /**
5
5
  * define eslint configurations
6
6
  * @param {Awaitable<Linter.Config | Linter.Config[]>[]} configs eslint flat configurations
@@ -3,6 +3,7 @@ export * from './imports.ts';
3
3
  export * from './javascript.ts';
4
4
  export * from './jsdoc.ts';
5
5
  export * from './jsonc.ts';
6
+ export * from './markdown.ts';
6
7
  export * from './prettier.ts';
7
8
  export * from './promise.ts';
8
9
  export * from './react.ts';
@@ -3,6 +3,7 @@ export * from './imports.ts';
3
3
  export * from './javascript.ts';
4
4
  export * from './jsdoc.ts';
5
5
  export * from './jsonc.ts';
6
+ export * from './markdown.ts';
6
7
  export * from './prettier.ts';
7
8
  export * from './promise.ts';
8
9
  export * from './react.ts';
@@ -0,0 +1,28 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { MarkdownRules, OverridesOptions } from '../types/index.ts';
3
+ /**
4
+ * eslint unicorn configuration options
5
+ */
6
+ export interface MarkdownOptions {
7
+ /**
8
+ * makrdown language
9
+ * @see https://github.com/eslint/markdown?tab=readme-ov-file#languages
10
+ * @default 'gfm'
11
+ */
12
+ language?: 'commonmark' | 'gfm';
13
+ /**
14
+ * enable fenced code blocks
15
+ * @see https://github.com/eslint/markdown/blob/main/docs/processors/markdown.md
16
+ * @default true
17
+ */
18
+ fencedCodeBlocks?: boolean;
19
+ }
20
+ /**
21
+ * `@eslint/markdown` and overrides configuration options
22
+ * @param {MarkdownOptions & OverridesOptions} options
23
+ * eslint unicorn configuration options
24
+ * @returns {Promise<Linter.Config[]>}
25
+ * eslint flat configurations with `@eslint/markdown` and overrides
26
+ */
27
+ export declare function markdown(options?: MarkdownOptions & OverridesOptions<MarkdownRules>): Promise<Linter.Config[]>;
28
+ export declare const md: typeof markdown;
@@ -0,0 +1,28 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { MarkdownRules, OverridesOptions } from '../types/index.ts';
3
+ /**
4
+ * eslint unicorn configuration options
5
+ */
6
+ export interface MarkdownOptions {
7
+ /**
8
+ * makrdown language
9
+ * @see https://github.com/eslint/markdown?tab=readme-ov-file#languages
10
+ * @default 'gfm'
11
+ */
12
+ language?: 'commonmark' | 'gfm';
13
+ /**
14
+ * enable fenced code blocks
15
+ * @see https://github.com/eslint/markdown/blob/main/docs/processors/markdown.md
16
+ * @default true
17
+ */
18
+ fencedCodeBlocks?: boolean;
19
+ }
20
+ /**
21
+ * `@eslint/markdown` and overrides configuration options
22
+ * @param {MarkdownOptions & OverridesOptions} options
23
+ * eslint unicorn configuration options
24
+ * @returns {Promise<Linter.Config[]>}
25
+ * eslint flat configurations with `@eslint/markdown` and overrides
26
+ */
27
+ export declare function markdown(options?: MarkdownOptions & OverridesOptions<MarkdownRules>): Promise<Linter.Config[]>;
28
+ export declare const md: typeof markdown;
package/dist/globs.d.cts CHANGED
@@ -9,5 +9,6 @@ export declare const GLOB_YAML = "**/*.y?(a)ml";
9
9
  export declare const GLOB_TOML = "**/*.toml";
10
10
  export declare const GLOB_VUE = "**/*.vue";
11
11
  export declare const GLOB_SVELTE = "**/*.svelte";
12
+ export declare const GLOB_MARKDOWN = "**/*.md";
12
13
  export declare const GLOB_TESTS: string[];
13
14
  export declare const GLOB_TESTS_TYPE: string[];
package/dist/globs.d.ts CHANGED
@@ -9,5 +9,6 @@ export declare const GLOB_YAML = "**/*.y?(a)ml";
9
9
  export declare const GLOB_TOML = "**/*.toml";
10
10
  export declare const GLOB_VUE = "**/*.vue";
11
11
  export declare const GLOB_SVELTE = "**/*.svelte";
12
+ export declare const GLOB_MARKDOWN = "**/*.md";
12
13
  export declare const GLOB_TESTS: string[];
13
14
  export declare const GLOB_TESTS_TYPE: string[];
package/dist/index.cjs CHANGED
@@ -23,6 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
 
24
24
  //#endregion
25
25
  const { FlatConfigComposer } = __toESM(require("eslint-flat-config-utils"));
26
+ const { interopDefault } = __toESM(require("@kazupon/jts-utils/module"));
26
27
  const { default: globals } = __toESM(require("globals"));
27
28
 
28
29
  //#region src/config.ts
@@ -31,13 +32,6 @@ function defineConfig(...configs) {
31
32
  return new FlatConfigComposer().append(...baseConfigs, ...configs);
32
33
  }
33
34
 
34
- //#endregion
35
- //#region node_modules/.pnpm/@kazupon+jts-utils@0.2.0/node_modules/@kazupon/jts-utils/dist/module/index.mjs
36
- async function interopDefault(mod) {
37
- const resolved = await mod;
38
- return resolved.default || resolved;
39
- }
40
-
41
35
  //#endregion
42
36
  //#region src/globs.ts
43
37
  const GLOB_JS = "**/*.?([cm])js";
@@ -51,8 +45,19 @@ const GLOB_YAML = "**/*.y?(a)ml";
51
45
  const GLOB_TOML = "**/*.toml";
52
46
  const GLOB_VUE = "**/*.vue";
53
47
  const GLOB_SVELTE = "**/*.svelte";
48
+ const GLOB_MARKDOWN = "**/*.md";
54
49
  const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
55
- const GLOB_TESTS = [`**/test/**/*.${GLOB_SRC_EXT}`, `**/tests/**/*.${GLOB_SRC_EXT}`, `**/spec/**/*.${GLOB_SRC_EXT}`, `**/specs/**/*.${GLOB_SRC_EXT}`, `**/e2e/**/*.${GLOB_SRC_EXT}`, `**/__tests__/**/*.${GLOB_SRC_EXT}`, `**/__test__/**/*.${GLOB_SRC_EXT}`, `**/*.spec.${GLOB_SRC_EXT}`, `**/*.test.${GLOB_SRC_EXT}`];
50
+ const GLOB_TESTS = [
51
+ `**/test/**/*.${GLOB_SRC_EXT}`,
52
+ `**/tests/**/*.${GLOB_SRC_EXT}`,
53
+ `**/spec/**/*.${GLOB_SRC_EXT}`,
54
+ `**/specs/**/*.${GLOB_SRC_EXT}`,
55
+ `**/e2e/**/*.${GLOB_SRC_EXT}`,
56
+ `**/__tests__/**/*.${GLOB_SRC_EXT}`,
57
+ `**/__test__/**/*.${GLOB_SRC_EXT}`,
58
+ `**/*.spec.${GLOB_SRC_EXT}`,
59
+ `**/*.test.${GLOB_SRC_EXT}`
60
+ ];
56
61
  const GLOB_TESTS_TYPE = [`**/*.test-d.${GLOB_SRC_EXT}`, `**/*.spec-d.${GLOB_SRC_EXT}`];
57
62
 
58
63
  //#endregion
@@ -69,7 +74,11 @@ async function getTypeScriptParser() {
69
74
  return ts.parser;
70
75
  }
71
76
  function getGlobSourceFiles(useTypeScript = false) {
72
- return [GLOB_JS, GLOB_JSX, ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []];
77
+ return [
78
+ GLOB_JS,
79
+ GLOB_JSX,
80
+ ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []
81
+ ];
73
82
  }
74
83
 
75
84
  //#endregion
@@ -89,17 +98,22 @@ async function comments(options = {}) {
89
98
 
90
99
  //#endregion
91
100
  //#region src/configs/imports.ts
92
- const IMPORTS_FILES = [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX];
101
+ const IMPORTS_FILES = [
102
+ GLOB_JS,
103
+ GLOB_JSX,
104
+ GLOB_TS,
105
+ GLOB_TSX
106
+ ];
93
107
  async function imports(options = {}) {
94
108
  const { rules: overrideRules = {} } = options;
95
109
  const unused = await loadPlugin("eslint-plugin-unused-imports");
96
- const importX = await loadPlugin("eslint-plugin-import-x");
97
- const configs = [importX.flatConfigs.recommended];
110
+ const imports$1 = await loadPlugin("eslint-plugin-import");
111
+ const configs = [imports$1.flatConfigs.recommended];
98
112
  if (options.typescript) {
99
113
  try {
100
114
  await loadPlugin("eslint-import-resolver-typescript");
101
- importX.flatConfigs.typescript.settings["import-x/resolver"]["typescript"] = true;
102
- configs.push(importX.flatConfigs.typescript);
115
+ imports$1.flatConfigs.typescript.settings["import/resolver"]["typescript"] = true;
116
+ configs.push(imports$1.flatConfigs.typescript);
103
117
  } catch (error) {
104
118
  throw new Error(`Not found eslint-import-resolver-typescript: ${error.message}`);
105
119
  }
@@ -192,7 +206,11 @@ async function jsdoc(options = {}) {
192
206
  //#region src/configs/jsonc.ts
193
207
  async function jsonc(options = {}) {
194
208
  const { rules: overrideRules = {} } = options;
195
- const kinds = [options.json ? "json" : "", options.jsonc ? "jsonc" : "", options.json5 ? "json5" : ""];
209
+ const kinds = [
210
+ options.json ? "json" : "",
211
+ options.jsonc ? "jsonc" : "",
212
+ options.json5 ? "json5" : ""
213
+ ];
196
214
  const usePrettier = !!options.prettier;
197
215
  const jsonc$1 = await loadPlugin("eslint-plugin-jsonc");
198
216
  const configs = [];
@@ -216,12 +234,20 @@ async function jsonc(options = {}) {
216
234
  }
217
235
  const overriddenConfig = {
218
236
  name: "@kazupon/jsonc",
219
- files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
237
+ files: [
238
+ GLOB_JSON,
239
+ GLOB_JSON5,
240
+ GLOB_JSONC
241
+ ],
220
242
  rules: { ...overrideRules }
221
243
  };
222
244
  configs.push(...jsoncSort(), overriddenConfig);
223
245
  return configs;
224
246
  }
247
+ /**
248
+ * jsonc sort configurations
249
+ * @returns {Linter.Config[]} jsonc sort configurations
250
+ */
225
251
  function jsoncSort() {
226
252
  return [{
227
253
  name: "@kazupon/jsonc/sort/package.json",
@@ -231,23 +257,94 @@ function jsoncSort() {
231
257
  order: { type: "asc" },
232
258
  pathPattern: "^files$"
233
259
  }],
234
- "jsonc/sort-keys": ["error", {
235
- order: ["name", "description", "private", "version", "author", "contributors", "license", "funding", "bugs", "repository", "keywords", "homepage", "publishConfig", "packageManager", "engines", "os", "cpu", "type", "sideEffects", "bin", "files", "main", "module", "browser", "unpkg", "jsdelivr", "directories", "exports", "types", "typesVersions", "scripts", "dependencies", "peerDependencies", "peerDependenciesMeta", "optionalDependencies", "devDependencies", "pnpm", "overrides", "resolutions", "workspaces", "prettier", "buildOptions", "lint-staged"],
236
- pathPattern: "^$"
237
- }, {
238
- order: { type: "asc" },
239
- pathPattern: "^scripts$"
240
- }, {
241
- order: { type: "asc" },
242
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
243
- }, {
244
- order: { type: "asc" },
245
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
246
- }]
260
+ "jsonc/sort-keys": [
261
+ "error",
262
+ {
263
+ order: [
264
+ "name",
265
+ "description",
266
+ "private",
267
+ "version",
268
+ "author",
269
+ "contributors",
270
+ "license",
271
+ "funding",
272
+ "bugs",
273
+ "repository",
274
+ "keywords",
275
+ "homepage",
276
+ "publishConfig",
277
+ "packageManager",
278
+ "engines",
279
+ "os",
280
+ "cpu",
281
+ "type",
282
+ "sideEffects",
283
+ "bin",
284
+ "files",
285
+ "main",
286
+ "module",
287
+ "browser",
288
+ "unpkg",
289
+ "jsdelivr",
290
+ "directories",
291
+ "exports",
292
+ "types",
293
+ "typesVersions",
294
+ "scripts",
295
+ "dependencies",
296
+ "peerDependencies",
297
+ "peerDependenciesMeta",
298
+ "optionalDependencies",
299
+ "devDependencies",
300
+ "pnpm",
301
+ "overrides",
302
+ "resolutions",
303
+ "workspaces",
304
+ "prettier",
305
+ "buildOptions",
306
+ "lint-staged"
307
+ ],
308
+ pathPattern: "^$"
309
+ },
310
+ {
311
+ order: { type: "asc" },
312
+ pathPattern: "^scripts$"
313
+ },
314
+ {
315
+ order: { type: "asc" },
316
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
317
+ },
318
+ {
319
+ order: { type: "asc" },
320
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
321
+ }
322
+ ]
247
323
  }
248
324
  }];
249
325
  }
250
326
 
327
+ //#endregion
328
+ //#region src/configs/markdown.ts
329
+ async function markdown(options = {}) {
330
+ const { rules: overrideRules = {} } = options;
331
+ const language = options.language || "gfm";
332
+ const fencedCodeBlocks = typeof options.fencedCodeBlocks === "boolean" ? options.fencedCodeBlocks : true;
333
+ const markdown$1 = await loadPlugin("@eslint/markdown");
334
+ const recommended = markdown$1.configs["recommended"][0];
335
+ recommended.language = `markdown/${language}`;
336
+ return [
337
+ recommended,
338
+ ...fencedCodeBlocks ? markdown$1.configs["processor"] : [],
339
+ {
340
+ name: "@kazupon/markdown",
341
+ files: [GLOB_MARKDOWN],
342
+ rules: { ...overrideRules }
343
+ }
344
+ ];
345
+ }
346
+ const md = markdown;
347
+
251
348
  //#endregion
252
349
  //#region src/configs/prettier.ts
253
350
  async function prettier(options = {}) {
@@ -279,7 +376,11 @@ async function react(options = {}) {
279
376
  const { rules: overrideRules = {}, settings = {} } = options;
280
377
  const useTypeScript = !options.typescript;
281
378
  const enableRefresh = !!options.refresh;
282
- const [react$1, reactHooks, reactRefresh] = await Promise.all([loadPlugin("eslint-plugin-react"), loadPlugin("eslint-plugin-react-hooks"), enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null]);
379
+ const [react$1, reactHooks, reactRefresh] = await Promise.all([
380
+ loadPlugin("eslint-plugin-react"),
381
+ loadPlugin("eslint-plugin-react-hooks"),
382
+ enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null
383
+ ]);
283
384
  const customConfig = {
284
385
  name: "@kazupon/react",
285
386
  files: getGlobSourceFiles(useTypeScript),
@@ -372,34 +473,50 @@ async function toml(options = {}) {
372
473
  async function typescript(options = {}) {
373
474
  const { rules: overrideRules = {}, extraFileExtensions = [], parserOptions = { project: true } } = options;
374
475
  const ts = await loadPlugin("typescript-eslint");
375
- const files = options.files ?? [GLOB_TS, GLOB_TSX, ...extraFileExtensions.map((ext) => `**/*${ext}`)];
376
- return [...ts.configs.recommendedTypeChecked, {
377
- files: [GLOB_JS, GLOB_JSX, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_YAML, GLOB_TOML],
378
- ...ts.configs.disableTypeChecked
379
- }, {
380
- name: "@kazupon/typescipt/typescript-eslint",
381
- files,
382
- languageOptions: {
383
- parser: ts.parser,
384
- parserOptions: {
385
- extraFileExtensions: extraFileExtensions.map((ext) => `${ext}`),
386
- sourceType: "module",
387
- ...parserOptions
388
- }
476
+ const files = options.files ?? [
477
+ GLOB_TS,
478
+ GLOB_TSX,
479
+ ...extraFileExtensions.map((ext) => `**/*${ext}`)
480
+ ];
481
+ return [
482
+ ...ts.configs.recommendedTypeChecked,
483
+ {
484
+ files: [
485
+ GLOB_JS,
486
+ GLOB_JSX,
487
+ GLOB_JSON,
488
+ GLOB_JSON5,
489
+ GLOB_JSONC,
490
+ GLOB_YAML,
491
+ GLOB_TOML
492
+ ],
493
+ ...ts.configs.disableTypeChecked
389
494
  },
390
- rules: {
391
- "@typescript-eslint/no-unused-vars": ["error", {
392
- args: "all",
393
- argsIgnorePattern: "^_",
394
- caughtErrors: "all",
395
- caughtErrorsIgnorePattern: "^_",
396
- destructuredArrayIgnorePattern: "^_",
397
- varsIgnorePattern: "^_",
398
- ignoreRestSiblings: true
399
- }],
400
- ...overrideRules
495
+ {
496
+ name: "@kazupon/typescipt/typescript-eslint",
497
+ files,
498
+ languageOptions: {
499
+ parser: ts.parser,
500
+ parserOptions: {
501
+ extraFileExtensions: extraFileExtensions.map((ext) => `${ext}`),
502
+ sourceType: "module",
503
+ ...parserOptions
504
+ }
505
+ },
506
+ rules: {
507
+ "@typescript-eslint/no-unused-vars": ["error", {
508
+ args: "all",
509
+ argsIgnorePattern: "^_",
510
+ caughtErrors: "all",
511
+ caughtErrorsIgnorePattern: "^_",
512
+ destructuredArrayIgnorePattern: "^_",
513
+ varsIgnorePattern: "^_",
514
+ ignoreRestSiblings: true
515
+ }],
516
+ ...overrideRules
517
+ }
401
518
  }
402
- }];
519
+ ];
403
520
  }
404
521
 
405
522
  //#endregion
@@ -575,6 +692,18 @@ Object.defineProperty(exports, 'jsonc', {
575
692
  return jsonc;
576
693
  }
577
694
  });
695
+ Object.defineProperty(exports, 'markdown', {
696
+ enumerable: true,
697
+ get: function () {
698
+ return markdown;
699
+ }
700
+ });
701
+ Object.defineProperty(exports, 'md', {
702
+ enumerable: true,
703
+ get: function () {
704
+ return md;
705
+ }
706
+ });
578
707
  Object.defineProperty(exports, 'prettier', {
579
708
  enumerable: true,
580
709
  get: function () {