@kazupon/eslint-config 0.12.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,9 @@ ESLint config for @kazupon
17
17
  - `promise`
18
18
  - `unicorn`
19
19
  - `prettier`
20
- - `vue`,
21
- - `svelte`,
20
+ - `vue`
21
+ - `react`
22
+ - `svelte`
22
23
  - `jsonc`
23
24
  - `yml`
24
25
  - `toml`
@@ -109,21 +110,22 @@ Add the following settings to your `.vscode/settings.json`:
109
110
 
110
111
  The following built-in configurations are supported:
111
112
 
112
- | Configuration | Powered by eslint plugin or package | Need to install eslint plugin or package? |
113
- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
114
- | `javascript` | [`@eslint/js`](https://www.npmjs.com/package/@eslint/js) | no (built-in) |
115
- | `comments` | [`@eslint-community/eslint-plugin-eslint-comments`](https://www.npmjs.com/package/@eslint-community/eslint-plugin-eslint-comments) | no (built-in) |
116
- | `typescript` | [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | yes |
117
- | `jsdoc` | [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) | yes |
118
- | `regexp` | [`eslint-plugin-regexp`](https://www.npmjs.com/package/eslint-plugin-regexp) | yes |
119
- | `promise` | [`eslint-plugin-promise`](https://www.npmjs.com/package/eslint-plugin-promise) | yes |
120
- | `unicorn` | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) | yes |
121
- | `prettier` | [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier) | yes |
122
- | `vue` | [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue) | yes |
123
- | `svelte` | [`eslint-plugin-svelte`](https://www.npmjs.com/package/eslint-plugin-svelte) | yes |
124
- | `jsonc` | [`eslint-plugin-jsonc`](https://www.npmjs.com/package/eslint-plugin-jsonc) | yes |
125
- | `yml` | [`eslint-plugin-yml`](https://www.npmjs.com/package/eslint-plugin-yml) | yes |
126
- | `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 |
127
129
 
128
130
  You can use `import` syntax:
129
131
 
@@ -10,4 +10,5 @@ export * from './prettier';
10
10
  export * from './jsonc';
11
11
  export * from './yml';
12
12
  export * from './vue';
13
+ export * from './react';
13
14
  export * from './svelte';
@@ -10,4 +10,5 @@ export * from './prettier';
10
10
  export * from './jsonc';
11
11
  export * from './yml';
12
12
  export * from './vue';
13
+ export * from './react';
13
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[]>;
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
@@ -333,10 +337,6 @@ async function vue(options = {}) {
333
337
  const useTypeScript = !!options.typescript;
334
338
  const vue$1 = await loadPlugin("eslint-plugin-vue");
335
339
  const vueParser = vue$1.configs["flat/base"][1]["languageOptions"]["parser"];
336
- async function getTypeScriptParser() {
337
- const ts = await loadPlugin("typescript-eslint");
338
- return ts.parser;
339
- }
340
340
  const customConfig = {
341
341
  name: "@kazupon/vue",
342
342
  files: [GLOB_VUE],
@@ -357,6 +357,47 @@ async function vue(options = {}) {
357
357
  return [...vue$1.configs["flat/recommended"], customConfig];
358
358
  }
359
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
+
360
401
  //#endregion
361
402
  //#region src/configs/svelte.ts
362
403
  async function svelte(options = {}) {
@@ -364,10 +405,6 @@ async function svelte(options = {}) {
364
405
  const useTypeScript = !!options.typescript;
365
406
  const svelte$1 = await loadPlugin("eslint-plugin-svelte");
366
407
  const svelteParser = svelte$1.configs["flat/base"][1]["languageOptions"]["parser"];
367
- async function getTypeScriptParser() {
368
- const ts = await loadPlugin("typescript-eslint");
369
- return ts.parser;
370
- }
371
408
  const customConfig = {
372
409
  name: "@kazupon/svelte",
373
410
  files: [GLOB_SVELTE],
@@ -431,6 +468,12 @@ Object.defineProperty(exports, 'promise', {
431
468
  return promise;
432
469
  }
433
470
  });
471
+ Object.defineProperty(exports, 'react', {
472
+ enumerable: true,
473
+ get: function () {
474
+ return react;
475
+ }
476
+ });
434
477
  Object.defineProperty(exports, 'regexp', {
435
478
  enumerable: true,
436
479
  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
@@ -309,10 +313,6 @@ async function vue(options = {}) {
309
313
  const useTypeScript = !!options.typescript;
310
314
  const vue$1 = await loadPlugin("eslint-plugin-vue");
311
315
  const vueParser = vue$1.configs["flat/base"][1]["languageOptions"]["parser"];
312
- async function getTypeScriptParser() {
313
- const ts = await loadPlugin("typescript-eslint");
314
- return ts.parser;
315
- }
316
316
  const customConfig = {
317
317
  name: "@kazupon/vue",
318
318
  files: [GLOB_VUE],
@@ -333,6 +333,47 @@ async function vue(options = {}) {
333
333
  return [...vue$1.configs["flat/recommended"], customConfig];
334
334
  }
335
335
 
336
+ //#endregion
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
+
336
377
  //#endregion
337
378
  //#region src/configs/svelte.ts
338
379
  async function svelte(options = {}) {
@@ -340,10 +381,6 @@ async function svelte(options = {}) {
340
381
  const useTypeScript = !!options.typescript;
341
382
  const svelte$1 = await loadPlugin("eslint-plugin-svelte");
342
383
  const svelteParser = svelte$1.configs["flat/base"][1]["languageOptions"]["parser"];
343
- async function getTypeScriptParser() {
344
- const ts = await loadPlugin("typescript-eslint");
345
- return ts.parser;
346
- }
347
384
  const customConfig = {
348
385
  name: "@kazupon/svelte",
349
386
  files: [GLOB_SVELTE],
@@ -365,4 +402,4 @@ async function svelte(options = {}) {
365
402
  }
366
403
 
367
404
  //#endregion
368
- export { comments, defineConfig, javascript, jsdoc, jsonc, prettier, promise, regexp, svelte, toml, typescript, unicorn, vue, yaml, yml };
405
+ export { comments, defineConfig, javascript, jsdoc, jsonc, prettier, promise, react, regexp, svelte, toml, typescript, unicorn, vue, yaml, yml };
@@ -4,6 +4,7 @@ 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';
8
9
  import type { SvelteRules } from './svelte';
9
10
  import type { TomlRules } from './toml';
@@ -13,7 +14,7 @@ import type { VueRules } from './vue';
13
14
  import type { YmlRules } from './yml';
14
15
  declare module 'eslint' {
15
16
  namespace Linter {
16
- interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
+ interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
18
  }
18
19
  }
19
20
  }
@@ -4,6 +4,7 @@ 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';
8
9
  import type { SvelteRules } from './svelte';
9
10
  import type { TomlRules } from './toml';
@@ -13,7 +14,7 @@ import type { VueRules } from './vue';
13
14
  import type { YmlRules } from './yml';
14
15
  declare module 'eslint' {
15
16
  namespace Linter {
16
- interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
+ interface RulesRecord extends CommentsRules, JavascriptRules, JsdocRules, JsoncRules, PrettierRules, PromiseRules, ReactRules, RegexpRules, SvelteRules, TomlRules, TypescriptRules, UnicornRules, VueRules, YmlRules {
17
18
  }
18
19
  }
19
20
  }