@kazupon/eslint-config 0.11.0 → 0.13.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
@@ -17,8 +17,10 @@ ESLint config for @kazupon
17
17
  - `promise`
18
18
  - `unicorn`
19
19
  - `prettier`
20
+ - `vue`
21
+ - `react`
22
+ - `svelte`
20
23
  - `jsonc`
21
- - `vue`,
22
24
  - `yml`
23
25
  - `toml`
24
26
  - Support primitive eslint flat configuration
@@ -88,7 +90,17 @@ Add the following settings to your `.vscode/settings.json`:
88
90
  "source.fixAll.eslint": "explicit"
89
91
  },
90
92
  // Enable eslint for supported languages
91
- "eslint.validate": ["javascript", "typescript", "json", "jsonc", "json5", "vue", "yaml", "toml"],
93
+ "eslint.validate": [
94
+ "javascript",
95
+ "typescript",
96
+ "vue",
97
+ "svelte",
98
+ "json",
99
+ "jsonc",
100
+ "json5",
101
+ "yaml",
102
+ "toml"
103
+ ],
92
104
  // Enable flat configuration
93
105
  "eslint.useFlatConfig": true
94
106
  }
@@ -98,20 +110,22 @@ Add the following settings to your `.vscode/settings.json`:
98
110
 
99
111
  The following built-in configurations are supported:
100
112
 
101
- | Configuration | Powered by eslint plugin or package | Need to install eslint plugin or package? |
102
- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
103
- | `javascript` | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) | no (built-in) |
104
- | `comments` | [`@eslint-community/eslint-plugin-eslint-comments`](https://www.npmjs.com/package/@eslint-community/eslint-plugin-eslint-comments) | no (built-in) |
105
- | `typescript` | [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | yes |
106
- | `jsdoc` | [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) | yes |
107
- | `regexp` | [`eslint-plugin-regexp`](https://www.npmjs.com/package/eslint-plugin-regexp) | yes |
108
- | `promise` | [`eslint-plugin-promise`](https://www.npmjs.com/package/eslint-plugin-promise) | yes |
109
- | `unicorn` | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) | yes |
110
- | `prettier` | [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier) | yes |
111
- | `jsonc` | [`eslint-plugin-jsonc`](https://www.npmjs.com/package/eslint-plugin-jsonc) | yes |
112
- | `vue` | [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue) | yes |
113
- | `yml` | [`eslint-plugin-yml`](https://www.npmjs.com/package/eslint-plugin-yml) | yes |
114
- | `toml` | [`eslint-plugin-toml`](https://www.npmjs.com/package/eslint-plugin-toml) | yes |
113
+ | Configuration | Powered by eslint plugin or package | Need to install eslint plugin or package? |
114
+ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
115
+ | `javascript` | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) | no (built-in) |
116
+ | `comments` | [`@eslint-community/eslint-plugin-eslint-comments`](https://www.npmjs.com/package/@eslint-community/eslint-plugin-eslint-comments) | no (built-in) |
117
+ | `typescript` | [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | yes |
118
+ | `jsdoc` | [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) | yes |
119
+ | `regexp` | [`eslint-plugin-regexp`](https://www.npmjs.com/package/eslint-plugin-regexp) | yes |
120
+ | `promise` | [`eslint-plugin-promise`](https://www.npmjs.com/package/eslint-plugin-promise) | yes |
121
+ | `unicorn` | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) | yes |
122
+ | `prettier` | [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier) | yes |
123
+ | `vue` | [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue) | yes |
124
+ | `react` | [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react), [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks), [`eslint-plugin-react-refresh`](https://www.npmjs.com/package/eslint-plugin-react-refresh) | yes |
125
+ | `svelte` | [`eslint-plugin-svelte`](https://www.npmjs.com/package/eslint-plugin-svelte) | yes |
126
+ | `jsonc` | [`eslint-plugin-jsonc`](https://www.npmjs.com/package/eslint-plugin-jsonc) | yes |
127
+ | `yml` | [`eslint-plugin-yml`](https://www.npmjs.com/package/eslint-plugin-yml) | yes |
128
+ | `toml` | [`eslint-plugin-toml`](https://www.npmjs.com/package/eslint-plugin-toml) | yes |
115
129
 
116
130
  You can use `import` syntax:
117
131
 
@@ -10,3 +10,5 @@ export * from './prettier';
10
10
  export * from './jsonc';
11
11
  export * from './yml';
12
12
  export * from './vue';
13
+ export * from './react';
14
+ export * from './svelte';
@@ -10,3 +10,5 @@ export * from './prettier';
10
10
  export * from './jsonc';
11
11
  export * from './yml';
12
12
  export * from './vue';
13
+ export * from './react';
14
+ export * from './svelte';
@@ -0,0 +1,26 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { TypeScriptOptions } from './typescript';
3
+ import type { OverridesOptions, ReactRules } from '../types';
4
+ /**
5
+ * eslint react configuration options
6
+ */
7
+ export interface ReactOptions {
8
+ /**
9
+ * use TypeScript
10
+ * @default true
11
+ */
12
+ typescript?: boolean;
13
+ /**
14
+ * enable `eslint-plugin-react-refresh` recommended rules
15
+ * @default false
16
+ */
17
+ refresh?: boolean;
18
+ }
19
+ /**
20
+ * `eslint-plugin-react` and overrides configuration options
21
+ * @param {ReactOptions & OverridesOptions} options
22
+ * eslint react configuration options for regular expressions
23
+ * @returns {Promise<Linter.Config[]>}
24
+ * eslint flat configurations with `eslint-plugin-react` and overrides
25
+ */
26
+ export declare function react(options?: ReactOptions & TypeScriptOptions & OverridesOptions<ReactRules>): Promise<Linter.Config[]>;
@@ -0,0 +1,26 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { TypeScriptOptions } from './typescript';
3
+ import type { OverridesOptions, ReactRules } from '../types';
4
+ /**
5
+ * eslint react configuration options
6
+ */
7
+ export interface ReactOptions {
8
+ /**
9
+ * use TypeScript
10
+ * @default true
11
+ */
12
+ typescript?: boolean;
13
+ /**
14
+ * enable `eslint-plugin-react-refresh` recommended rules
15
+ * @default false
16
+ */
17
+ refresh?: boolean;
18
+ }
19
+ /**
20
+ * `eslint-plugin-react` and overrides configuration options
21
+ * @param {ReactOptions & OverridesOptions} options
22
+ * eslint react configuration options for regular expressions
23
+ * @returns {Promise<Linter.Config[]>}
24
+ * eslint flat configurations with `eslint-plugin-react` and overrides
25
+ */
26
+ export declare function react(options?: ReactOptions & TypeScriptOptions & OverridesOptions<ReactRules>): Promise<Linter.Config[]>;
@@ -0,0 +1,21 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { TypeScriptOptions } from './typescript';
3
+ import type { OverridesOptions, SvelteRules } from '../types';
4
+ /**
5
+ * Svelte configuration options
6
+ */
7
+ export interface SvelteScriptOptions {
8
+ /**
9
+ * use TypeScript in `template` block
10
+ * @default false
11
+ */
12
+ typescript?: boolean;
13
+ }
14
+ /**
15
+ * `eslint-plugin-svelte` and overrides configuration options
16
+ * @param {SvelteScriptOptions & TypeScriptOptions & OverridesOptions} options
17
+ * eslint configuration options for Vue
18
+ * @returns {Promise<Linter.Config[]>}
19
+ * eslint flat configurations with `eslint-plugin-svelte` and overrides
20
+ */
21
+ export declare function svelte(options?: SvelteScriptOptions & TypeScriptOptions & OverridesOptions<SvelteRules>): Promise<Linter.Config[]>;
@@ -0,0 +1,21 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { TypeScriptOptions } from './typescript';
3
+ import type { OverridesOptions, SvelteRules } from '../types';
4
+ /**
5
+ * Svelte configuration options
6
+ */
7
+ export interface SvelteScriptOptions {
8
+ /**
9
+ * use TypeScript in `template` block
10
+ * @default false
11
+ */
12
+ typescript?: boolean;
13
+ }
14
+ /**
15
+ * `eslint-plugin-svelte` and overrides configuration options
16
+ * @param {SvelteScriptOptions & TypeScriptOptions & OverridesOptions} options
17
+ * eslint configuration options for Vue
18
+ * @returns {Promise<Linter.Config[]>}
19
+ * eslint flat configurations with `eslint-plugin-svelte` and overrides
20
+ */
21
+ export declare function svelte(options?: SvelteScriptOptions & TypeScriptOptions & OverridesOptions<SvelteRules>): Promise<Linter.Config[]>;
package/dist/globs.d.cts CHANGED
@@ -8,3 +8,4 @@ export declare const GLOB_JSONC = "**/*.jsonc";
8
8
  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
+ export declare const GLOB_SVELTE = "**/*.svelte";
package/dist/globs.d.ts CHANGED
@@ -8,3 +8,4 @@ export declare const GLOB_JSONC = "**/*.jsonc";
8
8
  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
+ export declare const GLOB_SVELTE = "**/*.svelte";
package/dist/index.cjs CHANGED
@@ -44,6 +44,10 @@ async function loadPlugin(name) {
44
44
  });
45
45
  return interopDefault(mod);
46
46
  }
47
+ async function getTypeScriptParser() {
48
+ const ts = await loadPlugin("typescript-eslint");
49
+ return ts.parser;
50
+ }
47
51
 
48
52
  //#endregion
49
53
  //#region src/configs/javascript.ts
@@ -104,6 +108,7 @@ const GLOB_JSONC = "**/*.jsonc";
104
108
  const GLOB_YAML = "**/*.y?(a)ml";
105
109
  const GLOB_TOML = "**/*.toml";
106
110
  const GLOB_VUE = "**/*.vue";
111
+ const GLOB_SVELTE = "**/*.svelte";
107
112
 
108
113
  //#endregion
109
114
  //#region src/configs/typescript.ts
@@ -332,10 +337,6 @@ async function vue(options = {}) {
332
337
  const useTypeScript = !!options.typescript;
333
338
  const vue$1 = await loadPlugin("eslint-plugin-vue");
334
339
  const vueParser = vue$1.configs["flat/base"][1]["languageOptions"]["parser"];
335
- async function getTypeScriptParser() {
336
- const ts = await loadPlugin("typescript-eslint");
337
- return ts.parser;
338
- }
339
340
  const customConfig = {
340
341
  name: "@kazupon/vue",
341
342
  files: [GLOB_VUE],
@@ -356,6 +357,74 @@ async function vue(options = {}) {
356
357
  return [...vue$1.configs["flat/recommended"], customConfig];
357
358
  }
358
359
 
360
+ //#endregion
361
+ //#region src/configs/react.ts
362
+ async function react(options = {}) {
363
+ const { rules: overrideRules = {}, parserOptions = { project: true }, settings = {} } = options;
364
+ const useTypeScript = !options.typescript;
365
+ const enableRefresh = !!options.refresh;
366
+ const [react$1, reactHooks, reactRefresh] = await Promise.all([loadPlugin("eslint-plugin-react"), loadPlugin("eslint-plugin-react-hooks"), enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null]);
367
+ function getFiles() {
368
+ return [GLOB_JS, GLOB_JSX, ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []];
369
+ }
370
+ const customConfig = {
371
+ name: "@kazupon/react",
372
+ files: getFiles(),
373
+ rules: { ...overrideRules }
374
+ };
375
+ if (useTypeScript) {
376
+ customConfig.languageOptions = {
377
+ parser: await getTypeScriptParser(),
378
+ parserOptions: { ...parserOptions }
379
+ };
380
+ }
381
+ const configs = [{
382
+ name: "react/flat/recommended",
383
+ files: getFiles(),
384
+ settings,
385
+ ...react$1.configs.flat.recommended
386
+ }, {
387
+ name: "react-hooks/flat",
388
+ files: getFiles(),
389
+ plugins: { "react-hooks": reactHooks }
390
+ }];
391
+ if (enableRefresh) {
392
+ configs.push({
393
+ name: "react-refresh/flat",
394
+ files: getFiles(),
395
+ plugins: { "react-refresh": reactRefresh }
396
+ });
397
+ }
398
+ return [...configs, customConfig];
399
+ }
400
+
401
+ //#endregion
402
+ //#region src/configs/svelte.ts
403
+ async function svelte(options = {}) {
404
+ const { rules: overrideRules = {}, parserOptions = { project: true } } = options;
405
+ const useTypeScript = !!options.typescript;
406
+ const svelte$1 = await loadPlugin("eslint-plugin-svelte");
407
+ const svelteParser = svelte$1.configs["flat/base"][1]["languageOptions"]["parser"];
408
+ const customConfig = {
409
+ name: "@kazupon/svelte",
410
+ files: [GLOB_SVELTE],
411
+ rules: { ...overrideRules }
412
+ };
413
+ if (useTypeScript) {
414
+ customConfig.languageOptions = {
415
+ parser: svelteParser,
416
+ parserOptions: {
417
+ sourceType: "module",
418
+ parser: await getTypeScriptParser(),
419
+ ecmaFeatures: { jsx: true },
420
+ extraFileExtensions: [".svelte"],
421
+ ...parserOptions
422
+ }
423
+ };
424
+ }
425
+ return [...svelte$1.configs["flat/recommended"], customConfig];
426
+ }
427
+
359
428
  //#endregion
360
429
  Object.defineProperty(exports, 'comments', {
361
430
  enumerable: true,
@@ -399,12 +468,24 @@ Object.defineProperty(exports, 'promise', {
399
468
  return promise;
400
469
  }
401
470
  });
471
+ Object.defineProperty(exports, 'react', {
472
+ enumerable: true,
473
+ get: function () {
474
+ return react;
475
+ }
476
+ });
402
477
  Object.defineProperty(exports, 'regexp', {
403
478
  enumerable: true,
404
479
  get: function () {
405
480
  return regexp;
406
481
  }
407
482
  });
483
+ Object.defineProperty(exports, 'svelte', {
484
+ enumerable: true,
485
+ get: function () {
486
+ return svelte;
487
+ }
488
+ });
408
489
  Object.defineProperty(exports, 'toml', {
409
490
  enumerable: true,
410
491
  get: function () {
package/dist/index.js CHANGED
@@ -20,6 +20,10 @@ async function loadPlugin(name) {
20
20
  });
21
21
  return interopDefault(mod);
22
22
  }
23
+ async function getTypeScriptParser() {
24
+ const ts = await loadPlugin("typescript-eslint");
25
+ return ts.parser;
26
+ }
23
27
 
24
28
  //#endregion
25
29
  //#region src/configs/javascript.ts
@@ -80,6 +84,7 @@ const GLOB_JSONC = "**/*.jsonc";
80
84
  const GLOB_YAML = "**/*.y?(a)ml";
81
85
  const GLOB_TOML = "**/*.toml";
82
86
  const GLOB_VUE = "**/*.vue";
87
+ const GLOB_SVELTE = "**/*.svelte";
83
88
 
84
89
  //#endregion
85
90
  //#region src/configs/typescript.ts
@@ -308,10 +313,6 @@ async function vue(options = {}) {
308
313
  const useTypeScript = !!options.typescript;
309
314
  const vue$1 = await loadPlugin("eslint-plugin-vue");
310
315
  const vueParser = vue$1.configs["flat/base"][1]["languageOptions"]["parser"];
311
- async function getTypeScriptParser() {
312
- const ts = await loadPlugin("typescript-eslint");
313
- return ts.parser;
314
- }
315
316
  const customConfig = {
316
317
  name: "@kazupon/vue",
317
318
  files: [GLOB_VUE],
@@ -333,4 +334,72 @@ async function vue(options = {}) {
333
334
  }
334
335
 
335
336
  //#endregion
336
- export { comments, defineConfig, javascript, jsdoc, jsonc, prettier, promise, regexp, toml, typescript, unicorn, vue, yaml, yml };
337
+ //#region src/configs/react.ts
338
+ async function react(options = {}) {
339
+ const { rules: overrideRules = {}, parserOptions = { project: true }, settings = {} } = options;
340
+ const useTypeScript = !options.typescript;
341
+ const enableRefresh = !!options.refresh;
342
+ const [react$1, reactHooks, reactRefresh] = await Promise.all([loadPlugin("eslint-plugin-react"), loadPlugin("eslint-plugin-react-hooks"), enableRefresh ? loadPlugin("eslint-plugin-react-refresh") : null]);
343
+ function getFiles() {
344
+ return [GLOB_JS, GLOB_JSX, ...useTypeScript ? [GLOB_TS, GLOB_TSX] : []];
345
+ }
346
+ const customConfig = {
347
+ name: "@kazupon/react",
348
+ files: getFiles(),
349
+ rules: { ...overrideRules }
350
+ };
351
+ if (useTypeScript) {
352
+ customConfig.languageOptions = {
353
+ parser: await getTypeScriptParser(),
354
+ parserOptions: { ...parserOptions }
355
+ };
356
+ }
357
+ const configs = [{
358
+ name: "react/flat/recommended",
359
+ files: getFiles(),
360
+ settings,
361
+ ...react$1.configs.flat.recommended
362
+ }, {
363
+ name: "react-hooks/flat",
364
+ files: getFiles(),
365
+ plugins: { "react-hooks": reactHooks }
366
+ }];
367
+ if (enableRefresh) {
368
+ configs.push({
369
+ name: "react-refresh/flat",
370
+ files: getFiles(),
371
+ plugins: { "react-refresh": reactRefresh }
372
+ });
373
+ }
374
+ return [...configs, customConfig];
375
+ }
376
+
377
+ //#endregion
378
+ //#region src/configs/svelte.ts
379
+ async function svelte(options = {}) {
380
+ const { rules: overrideRules = {}, parserOptions = { project: true } } = options;
381
+ const useTypeScript = !!options.typescript;
382
+ const svelte$1 = await loadPlugin("eslint-plugin-svelte");
383
+ const svelteParser = svelte$1.configs["flat/base"][1]["languageOptions"]["parser"];
384
+ const customConfig = {
385
+ name: "@kazupon/svelte",
386
+ files: [GLOB_SVELTE],
387
+ rules: { ...overrideRules }
388
+ };
389
+ if (useTypeScript) {
390
+ customConfig.languageOptions = {
391
+ parser: svelteParser,
392
+ parserOptions: {
393
+ sourceType: "module",
394
+ parser: await getTypeScriptParser(),
395
+ ecmaFeatures: { jsx: true },
396
+ extraFileExtensions: [".svelte"],
397
+ ...parserOptions
398
+ }
399
+ };
400
+ }
401
+ return [...svelte$1.configs["flat/recommended"], customConfig];
402
+ }
403
+
404
+ //#endregion
405
+ export { comments, defineConfig, javascript, jsdoc, jsonc, prettier, promise, react, regexp, svelte, toml, typescript, unicorn, vue, yaml, yml };
@@ -4,7 +4,9 @@ import type { JsdocRules } from './jsdoc';
4
4
  import type { JsoncRules } from './jsonc';
5
5
  import type { PrettierRules } from './prettier';
6
6
  import type { PromiseRules } from './promise';
7
+ import type { ReactRules } from './react';
7
8
  import type { RegexpRules } from './regexp';
9
+ import type { SvelteRules } from './svelte';
8
10
  import type { TomlRules } from './toml';
9
11
  import type { TypescriptRules } from './typescript';
10
12
  import type { UnicornRules } from './unicorn';
@@ -12,7 +14,7 @@ import type { VueRules } from './vue';
12
14
  import type { YmlRules } from './yml';
13
15
  declare module 'eslint' {
14
16
  namespace Linter {
15
- interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, RegexpRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
+ interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
16
18
  }
17
19
  }
18
20
  }
@@ -4,7 +4,9 @@ import type { JsdocRules } from './jsdoc';
4
4
  import type { JsoncRules } from './jsonc';
5
5
  import type { PrettierRules } from './prettier';
6
6
  import type { PromiseRules } from './promise';
7
+ import type { ReactRules } from './react';
7
8
  import type { RegexpRules } from './regexp';
9
+ import type { SvelteRules } from './svelte';
8
10
  import type { TomlRules } from './toml';
9
11
  import type { TypescriptRules } from './typescript';
10
12
  import type { UnicornRules } from './unicorn';
@@ -12,7 +14,7 @@ import type { VueRules } from './vue';
12
14
  import type { YmlRules } from './yml';
13
15
  declare module 'eslint' {
14
16
  namespace Linter {
15
- interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, RegexpRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
+ interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
16
18
  }
17
19
  }
18
20
  }