@kazupon/eslint-config 0.4.1 → 0.6.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
@@ -13,7 +13,10 @@ ESLint config for @kazupon
13
13
  - `comments`
14
14
  - `typescript`
15
15
  - `jsdoc`
16
+ - `regexp`
17
+ - `unicorn`
16
18
  - `prettier`
19
+ - `jsonc`
17
20
  - `vue`
18
21
  - Support primitive eslint flat configuration
19
22
  - Support overrides for built-in configurations
@@ -82,7 +85,7 @@ Add the following settings to your `.vscode/settings.json`:
82
85
  "source.fixAll.eslint": "explicit"
83
86
  },
84
87
  // Enable eslint for supported languages
85
- "eslint.validate": ["javascript", "typescript", "vue"],
88
+ "eslint.validate": ["javascript", "typescript", "json", "jsonc", "json5", "vue"],
86
89
  // Enable flat configuration
87
90
  "eslint.useFlatConfig": true
88
91
  }
@@ -98,7 +101,10 @@ The following built-in configurations are supported:
98
101
  | `comments` | [`eslint-plugin-eslint-comments`](https://www.npmjs.com/package/eslint-plugin-eslint-comments) | no (built-in) |
99
102
  | `typescript` | [`typescript-eslint`](https://www.npmjs.com/package/typescript-eslint) | yes |
100
103
  | `jsdoc` | [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) | yes |
104
+ | `regexp` | [`eslint-plugin-regexp`](https://www.npmjs.com/package/eslint-plugin-regexp) | yes |
105
+ | `unicorn` | [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) | yes |
101
106
  | `prettier` | [`eslint-config-prettier`](https://www.npmjs.com/package/eslint-config-prettier) | yes |
107
+ | `jsonc` | [`eslint-plugin-jsonc`](https://www.npmjs.com/package/eslint-plugin-jsonc) | yes |
102
108
  | `vue` | [`eslint-plugin-vue`](https://www.npmjs.com/package/eslint-plugin-vue) | yes |
103
109
 
104
110
  You can use `import` syntax:
@@ -2,5 +2,8 @@ export * from './javascript';
2
2
  export * from './comments';
3
3
  export * from './typescript';
4
4
  export * from './jsdoc';
5
+ export * from './regexp';
6
+ export * from './unicorn';
5
7
  export * from './prettier';
8
+ export * from './jsonc';
6
9
  export * from './vue';
@@ -2,5 +2,8 @@ export * from './javascript';
2
2
  export * from './comments';
3
3
  export * from './typescript';
4
4
  export * from './jsdoc';
5
+ export * from './regexp';
6
+ export * from './unicorn';
5
7
  export * from './prettier';
8
+ export * from './jsonc';
6
9
  export * from './vue';
@@ -1,7 +1,7 @@
1
1
  import type { Linter } from 'eslint';
2
2
  import type { OverridesOptions } from '../types';
3
- export interface JsDocOptions {
3
+ export interface JsDocumentOptions {
4
4
  typescript?: (('syntax') | ('flavor'));
5
5
  error?: boolean;
6
6
  }
7
- export declare function jsdoc(options?: ((JsDocOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
7
+ export declare function jsdoc(options?: ((JsDocumentOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -1,7 +1,7 @@
1
1
  import type { Linter } from 'eslint';
2
2
  import type { OverridesOptions } from '../types';
3
- export interface JsDocOptions {
3
+ export interface JsDocumentOptions {
4
4
  typescript?: (('syntax') | ('flavor'));
5
5
  error?: boolean;
6
6
  }
7
- export declare function jsdoc(options?: ((JsDocOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
7
+ export declare function jsdoc(options?: ((JsDocumentOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,9 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface JsoncOptions {
4
+ json?: boolean;
5
+ jsonc?: boolean;
6
+ json5?: boolean;
7
+ prettier?: boolean;
8
+ }
9
+ export declare function jsonc(options?: ((JsoncOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,9 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface JsoncOptions {
4
+ json?: boolean;
5
+ jsonc?: boolean;
6
+ json5?: boolean;
7
+ prettier?: boolean;
8
+ }
9
+ export declare function jsonc(options?: ((JsoncOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface RegexpOptions {}
4
+ export declare function regexp(options?: ((RegexpOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface RegexpOptions {}
4
+ export declare function regexp(options?: ((RegexpOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface UnicornOptions {}
4
+ export declare function unicorn(options?: ((UnicornOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
@@ -0,0 +1,4 @@
1
+ import type { Linter } from 'eslint';
2
+ import type { OverridesOptions } from '../types';
3
+ export interface UnicornOptions {}
4
+ export declare function unicorn(options?: ((UnicornOptions) & (OverridesOptions))): Promise<(Linter.FlatConfig)[]>;
package/dist/globs.d.cts CHANGED
@@ -3,3 +3,6 @@ export declare const GLOB_JSX = '**/*.?([cm])jsx';
3
3
  export declare const GLOB_TS = '**/*.?([cm])ts';
4
4
  export declare const GLOB_TSX = '**/*.?([cm])tsx';
5
5
  export declare const GLOB_VUE = '**/*.vue';
6
+ export declare const GLOB_JSON = '**/*.json';
7
+ export declare const GLOB_JSON5 = '**/*.json5';
8
+ export declare const GLOB_JSONC = '**/*.jsonc';
package/dist/globs.d.ts CHANGED
@@ -3,3 +3,6 @@ export declare const GLOB_JSX = '**/*.?([cm])jsx';
3
3
  export declare const GLOB_TS = '**/*.?([cm])ts';
4
4
  export declare const GLOB_TSX = '**/*.?([cm])tsx';
5
5
  export declare const GLOB_VUE = '**/*.vue';
6
+ export declare const GLOB_JSON = '**/*.json';
7
+ export declare const GLOB_JSON5 = '**/*.json5';
8
+ export declare const GLOB_JSONC = '**/*.jsonc';
package/dist/index.cjs CHANGED
@@ -39,8 +39,8 @@ async function interopDefault(mod) {
39
39
  return (resolved).default || resolved;
40
40
  }
41
41
  async function loadPlugin(name) {
42
- const mod = await import(name).catch((err) => {
43
- console.error(err);
42
+ const mod = await import(name).catch((error) => {
43
+ console.error(error);
44
44
  throw new Error(`Failed to load eslint plugin '${name}'. Please install it!`);
45
45
  });
46
46
  return interopDefault(mod);
@@ -100,6 +100,9 @@ const GLOB_JSX = '**/*.?([cm])jsx';
100
100
  const GLOB_TS = '**/*.?([cm])ts';
101
101
  const GLOB_TSX = '**/*.?([cm])tsx';
102
102
  const GLOB_VUE = '**/*.vue';
103
+ const GLOB_JSON = '**/*.json';
104
+ const GLOB_JSON5 = '**/*.json5';
105
+ const GLOB_JSONC = '**/*.jsonc';
103
106
 
104
107
  //#endregion
105
108
  //#region src/configs/typescript.ts
@@ -108,7 +111,7 @@ async function typescript(options = {}) {
108
111
  const ts = await loadPlugin('typescript-eslint');
109
112
  const files = options.files ?? [GLOB_TS, GLOB_TSX, ...extraFileExtensions.map((ext) => `**/*${ext}`)];
110
113
  return [...(ts.configs.recommendedTypeChecked), {
111
- files: [GLOB_JS, GLOB_JSX],
114
+ files: [GLOB_JS, GLOB_JSX, GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
112
115
  ...(ts.configs.disableTypeChecked)
113
116
  }, {
114
117
  name: '@kazupon/typescipt/typescript-eslint',
@@ -159,6 +162,31 @@ async function jsdoc(options = {}) {
159
162
  }];
160
163
  }
161
164
 
165
+ //#endregion
166
+ //#region src/configs/regexp.ts
167
+ async function regexp(options = {}) {
168
+ const { rules: overrideRules = {} } = options;
169
+ const regexp$1 = await loadPlugin('eslint-plugin-regexp');
170
+ return [{
171
+ name: 'regexp/flat/recommended',
172
+ ...(regexp$1.configs['flat/recommended'])
173
+ }, {
174
+ name: '@kazupon/eslint-regexp',
175
+ rules: {...overrideRules}
176
+ }];
177
+ }
178
+
179
+ //#endregion
180
+ //#region src/configs/unicorn.ts
181
+ async function unicorn(options = {}) {
182
+ const { rules: overrideRules = {} } = options;
183
+ const unicorn$1 = await loadPlugin('eslint-plugin-unicorn');
184
+ return [unicorn$1.configs['flat/recommended'], {
185
+ name: '@kazupon/unicorn',
186
+ rules: {...overrideRules}
187
+ }];
188
+ }
189
+
162
190
  //#endregion
163
191
  //#region src/configs/prettier.ts
164
192
  async function prettier(options = {}) {
@@ -170,6 +198,50 @@ async function prettier(options = {}) {
170
198
  }];
171
199
  }
172
200
 
201
+ //#endregion
202
+ //#region src/configs/jsonc.ts
203
+ async function jsonc(options = {}) {
204
+ const { rules: overrideRules = {} } = options;
205
+ const kinds = [options.json ? 'json' : '', options.jsonc ? 'jsonc' : '', options.json5 ? 'json5' : ''];
206
+ const usePrettier = !!options.prettier;
207
+ const jsonc$1 = await loadPlugin('eslint-plugin-jsonc');
208
+ const configs = [];
209
+ const defaultRules = {'jsonc/sort-keys': ['warn', 'asc', {
210
+ caseSensitive: true,
211
+ natural: false,
212
+ minKeys: 2,
213
+ allowLineSeparatedGroups: false
214
+ }]};
215
+ for (const kind of kinds) {
216
+ if (kind) {
217
+ configs.push(...jsonc$1.configs[`flat/recommended-with-${kind}`].map((config, index) => {
218
+ return config.name ? config : {
219
+ name: `jsonc/flat/recommended-with-${kind}/${index}`,
220
+ ...config
221
+ };
222
+ }));
223
+ }
224
+ }
225
+ if (usePrettier) {
226
+ configs.push(...jsonc$1.configs['flat/prettier'].map((config, index) => {
227
+ return config.name ? config : {
228
+ name: `jsonc/flat/prettier/${index}`,
229
+ ...config
230
+ };
231
+ }));
232
+ }
233
+ const overriddenConfig = {
234
+ name: '@kazupon/jsonc',
235
+ files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
236
+ rules: {
237
+ ...defaultRules,
238
+ ...overrideRules
239
+ }
240
+ };
241
+ configs.push(overriddenConfig);
242
+ return configs;
243
+ }
244
+
173
245
  //#endregion
174
246
  //#region src/configs/vue.ts
175
247
  async function vue(options = {}) {
@@ -207,6 +279,9 @@ exports.comments = comments;
207
279
  exports.defineConfig = defineConfig;
208
280
  exports.javascript = javascript;
209
281
  exports.jsdoc = jsdoc;
282
+ exports.jsonc = jsonc;
210
283
  exports.prettier = prettier;
284
+ exports.regexp = regexp;
211
285
  exports.typescript = typescript;
286
+ exports.unicorn = unicorn;
212
287
  exports.vue = vue;
package/dist/index.js CHANGED
@@ -14,8 +14,8 @@ async function interopDefault(mod) {
14
14
  return (resolved).default || resolved;
15
15
  }
16
16
  async function loadPlugin(name) {
17
- const mod = await import(name).catch((err) => {
18
- console.error(err);
17
+ const mod = await import(name).catch((error) => {
18
+ console.error(error);
19
19
  throw new Error(`Failed to load eslint plugin '${name}'. Please install it!`);
20
20
  });
21
21
  return interopDefault(mod);
@@ -75,6 +75,9 @@ const GLOB_JSX = '**/*.?([cm])jsx';
75
75
  const GLOB_TS = '**/*.?([cm])ts';
76
76
  const GLOB_TSX = '**/*.?([cm])tsx';
77
77
  const GLOB_VUE = '**/*.vue';
78
+ const GLOB_JSON = '**/*.json';
79
+ const GLOB_JSON5 = '**/*.json5';
80
+ const GLOB_JSONC = '**/*.jsonc';
78
81
 
79
82
  //#endregion
80
83
  //#region src/configs/typescript.ts
@@ -83,7 +86,7 @@ async function typescript(options = {}) {
83
86
  const ts = await loadPlugin('typescript-eslint');
84
87
  const files = options.files ?? [GLOB_TS, GLOB_TSX, ...extraFileExtensions.map((ext) => `**/*${ext}`)];
85
88
  return [...(ts.configs.recommendedTypeChecked), {
86
- files: [GLOB_JS, GLOB_JSX],
89
+ files: [GLOB_JS, GLOB_JSX, GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
87
90
  ...(ts.configs.disableTypeChecked)
88
91
  }, {
89
92
  name: '@kazupon/typescipt/typescript-eslint',
@@ -134,6 +137,31 @@ async function jsdoc(options = {}) {
134
137
  }];
135
138
  }
136
139
 
140
+ //#endregion
141
+ //#region src/configs/regexp.ts
142
+ async function regexp(options = {}) {
143
+ const { rules: overrideRules = {} } = options;
144
+ const regexp$1 = await loadPlugin('eslint-plugin-regexp');
145
+ return [{
146
+ name: 'regexp/flat/recommended',
147
+ ...(regexp$1.configs['flat/recommended'])
148
+ }, {
149
+ name: '@kazupon/eslint-regexp',
150
+ rules: {...overrideRules}
151
+ }];
152
+ }
153
+
154
+ //#endregion
155
+ //#region src/configs/unicorn.ts
156
+ async function unicorn(options = {}) {
157
+ const { rules: overrideRules = {} } = options;
158
+ const unicorn$1 = await loadPlugin('eslint-plugin-unicorn');
159
+ return [unicorn$1.configs['flat/recommended'], {
160
+ name: '@kazupon/unicorn',
161
+ rules: {...overrideRules}
162
+ }];
163
+ }
164
+
137
165
  //#endregion
138
166
  //#region src/configs/prettier.ts
139
167
  async function prettier(options = {}) {
@@ -145,6 +173,50 @@ async function prettier(options = {}) {
145
173
  }];
146
174
  }
147
175
 
176
+ //#endregion
177
+ //#region src/configs/jsonc.ts
178
+ async function jsonc(options = {}) {
179
+ const { rules: overrideRules = {} } = options;
180
+ const kinds = [options.json ? 'json' : '', options.jsonc ? 'jsonc' : '', options.json5 ? 'json5' : ''];
181
+ const usePrettier = !!options.prettier;
182
+ const jsonc$1 = await loadPlugin('eslint-plugin-jsonc');
183
+ const configs = [];
184
+ const defaultRules = {'jsonc/sort-keys': ['warn', 'asc', {
185
+ caseSensitive: true,
186
+ natural: false,
187
+ minKeys: 2,
188
+ allowLineSeparatedGroups: false
189
+ }]};
190
+ for (const kind of kinds) {
191
+ if (kind) {
192
+ configs.push(...jsonc$1.configs[`flat/recommended-with-${kind}`].map((config, index) => {
193
+ return config.name ? config : {
194
+ name: `jsonc/flat/recommended-with-${kind}/${index}`,
195
+ ...config
196
+ };
197
+ }));
198
+ }
199
+ }
200
+ if (usePrettier) {
201
+ configs.push(...jsonc$1.configs['flat/prettier'].map((config, index) => {
202
+ return config.name ? config : {
203
+ name: `jsonc/flat/prettier/${index}`,
204
+ ...config
205
+ };
206
+ }));
207
+ }
208
+ const overriddenConfig = {
209
+ name: '@kazupon/jsonc',
210
+ files: [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
211
+ rules: {
212
+ ...defaultRules,
213
+ ...overrideRules
214
+ }
215
+ };
216
+ configs.push(overriddenConfig);
217
+ return configs;
218
+ }
219
+
148
220
  //#endregion
149
221
  //#region src/configs/vue.ts
150
222
  async function vue(options = {}) {
@@ -177,4 +249,4 @@ async function vue(options = {}) {
177
249
  }
178
250
 
179
251
  //#endregion
180
- export { comments, defineConfig, javascript, jsdoc, prettier, typescript, vue };
252
+ export { comments, defineConfig, javascript, jsdoc, jsonc, prettier, regexp, typescript, unicorn, vue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kazupon/eslint-config",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "ESLint config for @kazupon",
5
5
  "keywords": [
6
6
  "config",
@@ -45,6 +45,9 @@
45
45
  "eslint": ">=8.56.0 || >=9.0.0",
46
46
  "eslint-config-prettier": ">=9.1.0",
47
47
  "eslint-plugin-jsdoc": ">=48.5.0",
48
+ "eslint-plugin-jsonc": ">=2.16.0",
49
+ "eslint-plugin-regexp": ">=2.6.0",
50
+ "eslint-plugin-unicorn": ">=54.0.0",
48
51
  "eslint-plugin-vue": ">=9.24.0",
49
52
  "typescript-eslint": ">=7.0.0"
50
53
  },
@@ -58,6 +61,15 @@
58
61
  "eslint-plugin-jsdoc": {
59
62
  "optional": true
60
63
  },
64
+ "eslint-plugin-jsonc": {
65
+ "optional": true
66
+ },
67
+ "eslint-plugin-regexp": {
68
+ "optional": true
69
+ },
70
+ "eslint-plugin-unicorn": {
71
+ "optional": true
72
+ },
61
73
  "eslint-plugin-vue": {
62
74
  "optional": true
63
75
  }
@@ -70,6 +82,9 @@
70
82
  "eslint": "^9.6.0",
71
83
  "eslint-config-prettier": "^9.1.0",
72
84
  "eslint-plugin-jsdoc": "^48.5.2",
85
+ "eslint-plugin-jsonc": "^2.16.0",
86
+ "eslint-plugin-regexp": "^2.6.0",
87
+ "eslint-plugin-unicorn": "^54.0.0",
73
88
  "eslint-plugin-vue": "^9.27.0",
74
89
  "gh-changelogen": "^0.2.8",
75
90
  "lint-staged": "^15.2.7",
@@ -79,7 +94,7 @@
79
94
  "tsx": "^4.16.2",
80
95
  "typescript": "^5.5.3",
81
96
  "typescript-eslint": "^7.15.0",
82
- "vitest": "^1.6.0"
97
+ "vitest": "^2.0.0"
83
98
  },
84
99
  "lint-staged": {
85
100
  "*.{json,md,yml}": [