@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/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { FlatConfigComposer } from "eslint-flat-config-utils";
2
+ import { interopDefault } from "@kazupon/jts-utils/module";
2
3
  import { default as globals } from "globals";
3
4
 
4
5
  //#region src/config.ts
@@ -7,13 +8,6 @@ function defineConfig(...configs) {
7
8
  return new FlatConfigComposer().append(...baseConfigs, ...configs);
8
9
  }
9
10
 
10
- //#endregion
11
- //#region node_modules/.pnpm/@kazupon+jts-utils@0.2.0/node_modules/@kazupon/jts-utils/dist/module/index.mjs
12
- async function interopDefault(mod) {
13
- const resolved = await mod;
14
- return resolved.default || resolved;
15
- }
16
-
17
11
  //#endregion
18
12
  //#region src/globs.ts
19
13
  const GLOB_JS = "**/*.?([cm])js";
@@ -27,8 +21,19 @@ const GLOB_YAML = "**/*.y?(a)ml";
27
21
  const GLOB_TOML = "**/*.toml";
28
22
  const GLOB_VUE = "**/*.vue";
29
23
  const GLOB_SVELTE = "**/*.svelte";
24
+ const GLOB_MARKDOWN = "**/*.md";
30
25
  const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
31
- 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}`];
26
+ const GLOB_TESTS = [
27
+ `**/test/**/*.${GLOB_SRC_EXT}`,
28
+ `**/tests/**/*.${GLOB_SRC_EXT}`,
29
+ `**/spec/**/*.${GLOB_SRC_EXT}`,
30
+ `**/specs/**/*.${GLOB_SRC_EXT}`,
31
+ `**/e2e/**/*.${GLOB_SRC_EXT}`,
32
+ `**/__tests__/**/*.${GLOB_SRC_EXT}`,
33
+ `**/__test__/**/*.${GLOB_SRC_EXT}`,
34
+ `**/*.spec.${GLOB_SRC_EXT}`,
35
+ `**/*.test.${GLOB_SRC_EXT}`
36
+ ];
32
37
  const GLOB_TESTS_TYPE = [`**/*.test-d.${GLOB_SRC_EXT}`, `**/*.spec-d.${GLOB_SRC_EXT}`];
33
38
 
34
39
  //#endregion
@@ -45,7 +50,11 @@ async function getTypeScriptParser() {
45
50
  return ts.parser;
46
51
  }
47
52
  function getGlobSourceFiles(useTypeScript = false) {
48
- return [GLOB_JS, GLOB_JSX, ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []];
53
+ return [
54
+ GLOB_JS,
55
+ GLOB_JSX,
56
+ ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []
57
+ ];
49
58
  }
50
59
 
51
60
  //#endregion
@@ -65,17 +74,22 @@ async function comments(options = {}) {
65
74
 
66
75
  //#endregion
67
76
  //#region src/configs/imports.ts
68
- const IMPORTS_FILES = [GLOB_JS, GLOB_JSX, GLOB_TS, GLOB_TSX];
77
+ const IMPORTS_FILES = [
78
+ GLOB_JS,
79
+ GLOB_JSX,
80
+ GLOB_TS,
81
+ GLOB_TSX
82
+ ];
69
83
  async function imports(options = {}) {
70
84
  const { rules: overrideRules = {} } = options;
71
85
  const unused = await loadPlugin("eslint-plugin-unused-imports");
72
- const importX = await loadPlugin("eslint-plugin-import-x");
73
- const configs = [importX.flatConfigs.recommended];
86
+ const imports$1 = await loadPlugin("eslint-plugin-import");
87
+ const configs = [imports$1.flatConfigs.recommended];
74
88
  if (options.typescript) {
75
89
  try {
76
90
  await loadPlugin("eslint-import-resolver-typescript");
77
- importX.flatConfigs.typescript.settings["import-x/resolver"]["typescript"] = true;
78
- configs.push(importX.flatConfigs.typescript);
91
+ imports$1.flatConfigs.typescript.settings["import/resolver"]["typescript"] = true;
92
+ configs.push(imports$1.flatConfigs.typescript);
79
93
  } catch (error) {
80
94
  throw new Error(`Not found eslint-import-resolver-typescript: ${error.message}`);
81
95
  }
@@ -168,7 +182,11 @@ async function jsdoc(options = {}) {
168
182
  //#region src/configs/jsonc.ts
169
183
  async function jsonc(options = {}) {
170
184
  const { rules: overrideRules = {} } = options;
171
- const kinds = [options.json ? "json" : "", options.jsonc ? "jsonc" : "", options.json5 ? "json5" : ""];
185
+ const kinds = [
186
+ options.json ? "json" : "",
187
+ options.jsonc ? "jsonc" : "",
188
+ options.json5 ? "json5" : ""
189
+ ];
172
190
  const usePrettier = !!options.prettier;
173
191
  const jsonc$1 = await loadPlugin("eslint-plugin-jsonc");
174
192
  const configs = [];
@@ -192,12 +210,20 @@ async function jsonc(options = {}) {
192
210
  }
193
211
  const overriddenConfig = {
194
212
  name: "@kazupon/jsonc",
195
- files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
213
+ files: [
214
+ GLOB_JSON,
215
+ GLOB_JSON5,
216
+ GLOB_JSONC
217
+ ],
196
218
  rules: { ...overrideRules }
197
219
  };
198
220
  configs.push(...jsoncSort(), overriddenConfig);
199
221
  return configs;
200
222
  }
223
+ /**
224
+ * jsonc sort configurations
225
+ * @returns {Linter.Config[]} jsonc sort configurations
226
+ */
201
227
  function jsoncSort() {
202
228
  return [{
203
229
  name: "@kazupon/jsonc/sort/package.json",
@@ -207,23 +233,94 @@ function jsoncSort() {
207
233
  order: { type: "asc" },
208
234
  pathPattern: "^files$"
209
235
  }],
210
- "jsonc/sort-keys": ["error", {
211
- 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"],
212
- pathPattern: "^$"
213
- }, {
214
- order: { type: "asc" },
215
- pathPattern: "^scripts$"
216
- }, {
217
- order: { type: "asc" },
218
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
219
- }, {
220
- order: { type: "asc" },
221
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
222
- }]
236
+ "jsonc/sort-keys": [
237
+ "error",
238
+ {
239
+ order: [
240
+ "name",
241
+ "description",
242
+ "private",
243
+ "version",
244
+ "author",
245
+ "contributors",
246
+ "license",
247
+ "funding",
248
+ "bugs",
249
+ "repository",
250
+ "keywords",
251
+ "homepage",
252
+ "publishConfig",
253
+ "packageManager",
254
+ "engines",
255
+ "os",
256
+ "cpu",
257
+ "type",
258
+ "sideEffects",
259
+ "bin",
260
+ "files",
261
+ "main",
262
+ "module",
263
+ "browser",
264
+ "unpkg",
265
+ "jsdelivr",
266
+ "directories",
267
+ "exports",
268
+ "types",
269
+ "typesVersions",
270
+ "scripts",
271
+ "dependencies",
272
+ "peerDependencies",
273
+ "peerDependenciesMeta",
274
+ "optionalDependencies",
275
+ "devDependencies",
276
+ "pnpm",
277
+ "overrides",
278
+ "resolutions",
279
+ "workspaces",
280
+ "prettier",
281
+ "buildOptions",
282
+ "lint-staged"
283
+ ],
284
+ pathPattern: "^$"
285
+ },
286
+ {
287
+ order: { type: "asc" },
288
+ pathPattern: "^scripts$"
289
+ },
290
+ {
291
+ order: { type: "asc" },
292
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
293
+ },
294
+ {
295
+ order: { type: "asc" },
296
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
297
+ }
298
+ ]
223
299
  }
224
300
  }];
225
301
  }
226
302
 
303
+ //#endregion
304
+ //#region src/configs/markdown.ts
305
+ async function markdown(options = {}) {
306
+ const { rules: overrideRules = {} } = options;
307
+ const language = options.language || "gfm";
308
+ const fencedCodeBlocks = typeof options.fencedCodeBlocks === "boolean" ? options.fencedCodeBlocks : true;
309
+ const markdown$1 = await loadPlugin("@eslint/markdown");
310
+ const recommended = markdown$1.configs["recommended"][0];
311
+ recommended.language = `markdown/${language}`;
312
+ return [
313
+ recommended,
314
+ ...fencedCodeBlocks ? markdown$1.configs["processor"] : [],
315
+ {
316
+ name: "@kazupon/markdown",
317
+ files: [GLOB_MARKDOWN],
318
+ rules: { ...overrideRules }
319
+ }
320
+ ];
321
+ }
322
+ const md = markdown;
323
+
227
324
  //#endregion
228
325
  //#region src/configs/prettier.ts
229
326
  async function prettier(options = {}) {
@@ -255,7 +352,11 @@ async function react(options = {}) {
255
352
  const { rules: overrideRules = {}, settings = {} } = options;
256
353
  const useTypeScript = !options.typescript;
257
354
  const enableRefresh = !!options.refresh;
258
- const [react$1, reactHooks, reactRefresh] = await Promise.all([loadPlugin("eslint-plugin-react"), loadPlugin("eslint-plugin-react-hooks"), enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null]);
355
+ const [react$1, reactHooks, reactRefresh] = await Promise.all([
356
+ loadPlugin("eslint-plugin-react"),
357
+ loadPlugin("eslint-plugin-react-hooks"),
358
+ enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null
359
+ ]);
259
360
  const customConfig = {
260
361
  name: "@kazupon/react",
261
362
  files: getGlobSourceFiles(useTypeScript),
@@ -348,34 +449,50 @@ async function toml(options = {}) {
348
449
  async function typescript(options = {}) {
349
450
  const { rules: overrideRules = {}, extraFileExtensions = [], parserOptions = { project: true } } = options;
350
451
  const ts = await loadPlugin("typescript-eslint");
351
- const files = options.files ?? [GLOB_TS, GLOB_TSX, ...extraFileExtensions.map((ext) => `**/*${ext}`)];
352
- return [...ts.configs.recommendedTypeChecked, {
353
- files: [GLOB_JS, GLOB_JSX, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_YAML, GLOB_TOML],
354
- ...ts.configs.disableTypeChecked
355
- }, {
356
- name: "@kazupon/typescipt/typescript-eslint",
357
- files,
358
- languageOptions: {
359
- parser: ts.parser,
360
- parserOptions: {
361
- extraFileExtensions: extraFileExtensions.map((ext) => `${ext}`),
362
- sourceType: "module",
363
- ...parserOptions
364
- }
452
+ const files = options.files ?? [
453
+ GLOB_TS,
454
+ GLOB_TSX,
455
+ ...extraFileExtensions.map((ext) => `**/*${ext}`)
456
+ ];
457
+ return [
458
+ ...ts.configs.recommendedTypeChecked,
459
+ {
460
+ files: [
461
+ GLOB_JS,
462
+ GLOB_JSX,
463
+ GLOB_JSON,
464
+ GLOB_JSON5,
465
+ GLOB_JSONC,
466
+ GLOB_YAML,
467
+ GLOB_TOML
468
+ ],
469
+ ...ts.configs.disableTypeChecked
365
470
  },
366
- rules: {
367
- "@typescript-eslint/no-unused-vars": ["error", {
368
- args: "all",
369
- argsIgnorePattern: "^_",
370
- caughtErrors: "all",
371
- caughtErrorsIgnorePattern: "^_",
372
- destructuredArrayIgnorePattern: "^_",
373
- varsIgnorePattern: "^_",
374
- ignoreRestSiblings: true
375
- }],
376
- ...overrideRules
471
+ {
472
+ name: "@kazupon/typescipt/typescript-eslint",
473
+ files,
474
+ languageOptions: {
475
+ parser: ts.parser,
476
+ parserOptions: {
477
+ extraFileExtensions: extraFileExtensions.map((ext) => `${ext}`),
478
+ sourceType: "module",
479
+ ...parserOptions
480
+ }
481
+ },
482
+ rules: {
483
+ "@typescript-eslint/no-unused-vars": ["error", {
484
+ args: "all",
485
+ argsIgnorePattern: "^_",
486
+ caughtErrors: "all",
487
+ caughtErrorsIgnorePattern: "^_",
488
+ destructuredArrayIgnorePattern: "^_",
489
+ varsIgnorePattern: "^_",
490
+ ignoreRestSiblings: true
491
+ }],
492
+ ...overrideRules
493
+ }
377
494
  }
378
- }];
495
+ ];
379
496
  }
380
497
 
381
498
  //#endregion
@@ -515,4 +632,4 @@ async function yml(options = {}) {
515
632
  const yaml = yml;
516
633
 
517
634
  //#endregion
518
- export { comments, defineConfig, imports, javascript, jsdoc, jsonc, prettier, promise, react, regexp, svelte, toml, typescript, unicorn, vitest, vue, yaml, yml };
635
+ export { comments, defineConfig, imports, javascript, jsdoc, jsonc, markdown, md, prettier, promise, react, regexp, svelte, toml, typescript, unicorn, vitest, vue, yaml, yml };
@@ -3,6 +3,7 @@ import type { ImportsRules } from './imports';
3
3
  import type { JavascriptRules } from './javascript';
4
4
  import type { JsdocRules } from './jsdoc';
5
5
  import type { JsoncRules } from './jsonc';
6
+ import type { MarkdownRules } from './markdown';
6
7
  import type { PrettierRules } from './prettier';
7
8
  import type { PromiseRules } from './promise';
8
9
  import type { ReactRules } from './react';
@@ -16,7 +17,7 @@ import type { VueRules } from './vue';
16
17
  import type { YmlRules } from './yml';
17
18
  declare module 'eslint' {
18
19
  namespace Linter {
19
- interface RulesRecord extends CommentsRules, ImportsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VitestRules, VueRules, YmlRules {
20
+ interface RulesRecord extends CommentsRules, ImportsRules, JavascriptRules, JsdocRules, JsoncRules, MarkdownRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VitestRules, VueRules, YmlRules {
20
21
  }
21
22
  }
22
23
  }
@@ -3,6 +3,7 @@ import type { ImportsRules } from './imports';
3
3
  import type { JavascriptRules } from './javascript';
4
4
  import type { JsdocRules } from './jsdoc';
5
5
  import type { JsoncRules } from './jsonc';
6
+ import type { MarkdownRules } from './markdown';
6
7
  import type { PrettierRules } from './prettier';
7
8
  import type { PromiseRules } from './promise';
8
9
  import type { ReactRules } from './react';
@@ -16,7 +17,7 @@ import type { VueRules } from './vue';
16
17
  import type { YmlRules } from './yml';
17
18
  declare module 'eslint' {
18
19
  namespace Linter {
19
- interface RulesRecord extends CommentsRules, ImportsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VitestRules, VueRules, YmlRules {
20
+ interface RulesRecord extends CommentsRules, ImportsRules, JavascriptRules, JsdocRules, JsoncRules, MarkdownRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VitestRules, VueRules, YmlRules {
20
21
  }
21
22
  }
22
23
  }