@deot/dev-eslint 2.9.8 → 2.9.10

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,392 +1,303 @@
1
- import pluginTs from '@typescript-eslint/eslint-plugin';
2
- import * as parserTs from '@typescript-eslint/parser';
3
- import js from '@eslint/js';
4
- import globals from 'globals';
5
- import pluginJsdoc from 'eslint-plugin-jsdoc';
6
- import pluginMarkdown from 'eslint-plugin-markdown';
7
- import pluginImport from 'eslint-plugin-import-x';
8
- import pluginStylistic from '@stylistic/eslint-plugin';
9
- import pluginVue from 'eslint-plugin-vue';
10
- import parserVue from 'vue-eslint-parser';
11
-
12
- const pickOptions = async (key, options) => {
13
- const configOptions = {
14
- enable: typeof options?.[key] === "boolean" ? options[key] : true,
15
- overrides: {},
16
- ...typeof options?.[key] === "object" ? options[key] : {}
17
- };
18
- const overrides = options?.overrides?.[key] || {};
19
- return {
20
- ...configOptions,
21
- overrides: {
22
- ...configOptions.overrides,
23
- ...overrides
24
- }
25
- };
1
+ import pluginTs from "@typescript-eslint/eslint-plugin";
2
+ import * as parserTs from "@typescript-eslint/parser";
3
+ import js from "@eslint/js";
4
+ import globals from "globals";
5
+ import pluginJsdoc from "eslint-plugin-jsdoc";
6
+ import pluginMarkdown from "eslint-plugin-markdown";
7
+ import pluginImport from "eslint-plugin-import-x";
8
+ import pluginStylistic from "@stylistic/eslint-plugin";
9
+ import pluginVue from "eslint-plugin-vue";
10
+ import parserVue from "vue-eslint-parser";
11
+ //#region packages/eslint/src/configs/_helper.ts
12
+ var pickOptions = async (key, options) => {
13
+ const configOptions = {
14
+ enable: typeof options?.[key] === "boolean" ? options[key] : true,
15
+ overrides: {},
16
+ ...typeof options?.[key] === "object" ? options[key] : {}
17
+ };
18
+ const overrides = options?.overrides?.[key] || {};
19
+ return {
20
+ ...configOptions,
21
+ overrides: {
22
+ ...configOptions.overrides,
23
+ ...overrides
24
+ }
25
+ };
26
26
  };
27
- const cleanRules = (key, all, recommended, current) => {
28
- current = JSON.parse(JSON.stringify(current));
29
- const deprecated = [];
30
- const removed = [];
31
- const invaild = [];
32
- const keys = Object.keys(current);
33
- keys.forEach((i) => {
34
- if (all[i] === void 0 && recommended[i] === void 0) {
35
- removed.push(i);
36
- }
37
- if (recommended[i] === void 0 && (all[i] !== 0 && all[i] !== "off") && (current[i] === 0 || current[i] === "off")) {
38
- invaild.push(i);
39
- }
40
- });
41
- Object.keys(recommended).forEach((i) => {
42
- if (all[i] === void 0) {
43
- deprecated.push(i);
44
- delete current[i];
45
- }
46
- });
47
- const isTest = process.env.NODE_ENV === "UNIT" && !process.env.CI;
48
- if (isTest && removed.length) {
49
- console.error(key + ": " + removed.join(",") + " has removed!\n");
50
- }
51
- if (isTest && invaild.length) {
52
- console.error(key + ": " + invaild.join(",") + " has off default!\n");
53
- }
54
- if (isTest && deprecated.length) {
55
- console.error(key + ": " + deprecated.join(",") + " has deprecated!\n");
56
- }
57
- return current;
27
+ var cleanRules = (key, all, recommended, current) => {
28
+ current = JSON.parse(JSON.stringify(current));
29
+ const deprecated = [];
30
+ const removed = [];
31
+ const invaild = [];
32
+ Object.keys(current).forEach((i) => {
33
+ /* istanbul ignore next -- @preserve */
34
+ if (all[i] === void 0 && recommended[i] === void 0) removed.push(i);
35
+ /* istanbul ignore next -- @preserve */
36
+ if (recommended[i] === void 0 && all[i] !== 0 && all[i] !== "off" && (current[i] === 0 || current[i] === "off")) invaild.push(i);
37
+ });
38
+ Object.keys(recommended).forEach((i) => {
39
+ if (all[i] === void 0) {
40
+ deprecated.push(i);
41
+ delete current[i];
42
+ }
43
+ });
44
+ const isTest = process.env.NODE_ENV === "UNIT" && !process.env.CI;
45
+ /* istanbul ignore next -- @preserve */
46
+ if (isTest && removed.length) console.error(key + ": " + removed.join(",") + " has removed!\n");
47
+ /* istanbul ignore next -- @preserve */
48
+ if (isTest && invaild.length) console.error(key + ": " + invaild.join(",") + " has off default!\n");
49
+ /* istanbul ignore next -- @preserve */
50
+ if (isTest && deprecated.length) console.error(key + ": " + deprecated.join(",") + " has deprecated!\n");
51
+ return current;
58
52
  };
59
-
60
- const typescript = async (options$) => {
61
- const options = await pickOptions("typescript", options$);
62
- if (!options.enable) {
63
- return [];
64
- }
65
- const recommendedRules = pluginTs.configs["eslint-recommended"].overrides[0].rules;
66
- const allRules = pluginTs.configs["all"].rules;
67
- const rules = {
68
- ...recommendedRules,
69
- "@typescript-eslint/no-shadow": 2,
70
- // https://github.com/typescript-eslint/typescript-eslint/issues/2483
71
- "@typescript-eslint/no-unused-vars": 1,
72
- // ignore duplicate rules
73
- "no-unused-vars": 0
74
- };
75
- return [
76
- // 单独安装plugins, 方便扩展
77
- {
78
- plugins: {
79
- "@typescript-eslint": pluginTs
80
- }
81
- },
82
- {
83
- files: ["*.ts", "*.tsx", "*.mts", "*.cts"].map((i) => "**/" + i),
84
- languageOptions: {
85
- parser: parserTs,
86
- parserOptions: {
87
- sourceType: "module"
88
- }
89
- },
90
- rules: {
91
- ...cleanRules(
92
- "typescript",
93
- { ...allRules, ...recommendedRules },
94
- // all使用了extends, 但这里使用flat config
95
- recommendedRules,
96
- rules
97
- ),
98
- ...options.overrides
99
- }
100
- }
101
- ];
53
+ //#endregion
54
+ //#region packages/eslint/src/configs/typescript.ts
55
+ var typescript = async (options$) => {
56
+ const options = await pickOptions("typescript", options$);
57
+ if (!options.enable) return [];
58
+ const recommendedRules = pluginTs.configs["eslint-recommended"].overrides[0].rules;
59
+ const allRules = pluginTs.configs["all"].rules;
60
+ const rules = {
61
+ ...recommendedRules,
62
+ "@typescript-eslint/no-shadow": 2,
63
+ "@typescript-eslint/no-unused-vars": 1,
64
+ "no-unused-vars": 0
65
+ };
66
+ return [{ plugins: { "@typescript-eslint": pluginTs } }, {
67
+ files: [
68
+ "*.ts",
69
+ "*.tsx",
70
+ "*.mts",
71
+ "*.cts"
72
+ ].map((i) => "**/" + i),
73
+ languageOptions: {
74
+ parser: parserTs,
75
+ parserOptions: { sourceType: "module" }
76
+ },
77
+ rules: {
78
+ ...cleanRules("typescript", {
79
+ ...allRules,
80
+ ...recommendedRules
81
+ }, recommendedRules, rules),
82
+ ...options.overrides
83
+ }
84
+ }];
102
85
  };
103
-
104
- const javascript = async (options$) => {
105
- const options = await pickOptions("javascript", options$);
106
- if (!options.enable) {
107
- return [];
108
- }
109
- const allRules = js.configs.all.rules;
110
- const recommendedRules = js.configs.recommended.rules;
111
- const rules = {
112
- ...recommendedRules,
113
- "no-undef": 1,
114
- "no-debugger": 1,
115
- "no-unused-vars": 1,
116
- "no-useless-escape": 0,
117
- "prefer-const": [
118
- 2,
119
- {
120
- destructuring: "all",
121
- ignoreReadBeforeAssign: false
122
- }
123
- ]
124
- };
125
- return [
126
- {
127
- languageOptions: {
128
- ecmaVersion: "latest",
129
- globals: {
130
- ...globals.browser,
131
- ...globals.es2021,
132
- ...globals.node
133
- },
134
- parserOptions: {
135
- ecmaFeatures: {
136
- jsx: true
137
- },
138
- ecmaVersion: 2022,
139
- sourceType: "module"
140
- },
141
- sourceType: "module"
142
- },
143
- rules: {
144
- ...cleanRules("javascript", allRules, recommendedRules, rules),
145
- ...options.overrides
146
- }
147
- }
148
- ];
86
+ //#endregion
87
+ //#region packages/eslint/src/configs/javascript.ts
88
+ var javascript = async (options$) => {
89
+ const options = await pickOptions("javascript", options$);
90
+ if (!options.enable) return [];
91
+ const allRules = js.configs.all.rules;
92
+ const recommendedRules = js.configs.recommended.rules;
93
+ const rules = {
94
+ ...recommendedRules,
95
+ "no-undef": 1,
96
+ "no-debugger": 1,
97
+ "no-unused-vars": 1,
98
+ "no-useless-escape": 0,
99
+ "prefer-const": [2, {
100
+ destructuring: "all",
101
+ ignoreReadBeforeAssign: false
102
+ }]
103
+ };
104
+ return [{
105
+ languageOptions: {
106
+ ecmaVersion: "latest",
107
+ globals: {
108
+ ...globals.browser,
109
+ ...globals.es2021,
110
+ ...globals.node
111
+ },
112
+ parserOptions: {
113
+ ecmaFeatures: { jsx: true },
114
+ ecmaVersion: 2022,
115
+ sourceType: "module"
116
+ },
117
+ sourceType: "module"
118
+ },
119
+ rules: {
120
+ ...cleanRules("javascript", allRules, recommendedRules, rules),
121
+ ...options.overrides
122
+ }
123
+ }];
149
124
  };
150
-
151
- const jsdoc = async (options$) => {
152
- const options = await pickOptions("jsdoc", options$);
153
- if (!options.enable) {
154
- return [];
155
- }
156
- const recommendedRules = pluginJsdoc.configs["flat/recommended-typescript"].rules;
157
- const rules = {
158
- ...recommendedRules,
159
- "jsdoc/check-tag-names": 0
160
- };
161
- return [
162
- // 单独安装plugins,
163
- {
164
- plugins: {
165
- jsdoc: pluginJsdoc
166
- }
167
- },
168
- {
169
- rules: {
170
- ...cleanRules("jsdoc", recommendedRules, recommendedRules, rules),
171
- ...options.overrides
172
- }
173
- }
174
- ];
125
+ //#endregion
126
+ //#region packages/eslint/src/configs/jsdoc.ts
127
+ var jsdoc = async (options$) => {
128
+ const options = await pickOptions("jsdoc", options$);
129
+ if (!options.enable) return [];
130
+ const recommendedRules = pluginJsdoc.configs["flat/recommended-typescript"].rules;
131
+ const rules = {
132
+ ...recommendedRules,
133
+ "jsdoc/check-tag-names": 0
134
+ };
135
+ return [{ plugins: { jsdoc: pluginJsdoc } }, { rules: {
136
+ ...cleanRules("jsdoc", recommendedRules, recommendedRules, rules),
137
+ ...options.overrides
138
+ } }];
175
139
  };
176
-
177
- const markdown = async (options$) => {
178
- const options = await pickOptions("markdown", options$);
179
- if (!options.enable) {
180
- return [];
181
- }
182
- const config = pluginMarkdown.configs.recommended[2];
183
- return [
184
- {
185
- plugins: {
186
- markdown: pluginMarkdown
187
- }
188
- },
189
- {
190
- files: ["**/*.md"],
191
- processor: "markdown/markdown"
192
- },
193
- {
194
- files: ["**/*.md/*.ts"],
195
- rules: {
196
- "@typescript-eslint/no-unused-vars": 0
197
- }
198
- },
199
- {
200
- files: ["**/*.md/**"],
201
- languageOptions: {
202
- parserOptions: {
203
- ecmaFeatures: {
204
- impliedStrict: true
205
- }
206
- }
207
- },
208
- rules: {
209
- ...config.rules,
210
- "no-console": 1,
211
- ...options.overrides
212
- }
213
- }
214
- ];
140
+ //#endregion
141
+ //#region packages/eslint/src/configs/markdown.ts
142
+ var markdown = async (options$) => {
143
+ const options = await pickOptions("markdown", options$);
144
+ if (!options.enable) return [];
145
+ const config = pluginMarkdown.configs.recommended[2];
146
+ return [
147
+ { plugins: { markdown: pluginMarkdown } },
148
+ {
149
+ files: ["**/*.md"],
150
+ processor: "markdown/markdown"
151
+ },
152
+ {
153
+ files: ["**/*.md/*.ts"],
154
+ rules: { "@typescript-eslint/no-unused-vars": 0 }
155
+ },
156
+ {
157
+ files: ["**/*.md/**"],
158
+ languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } },
159
+ rules: {
160
+ ...config.rules,
161
+ "no-console": 1,
162
+ ...options.overrides
163
+ }
164
+ }
165
+ ];
215
166
  };
216
-
217
- const ignores = async (ignores$ = []) => {
218
- let defaults = [
219
- "**/node_modules",
220
- "**/dist",
221
- "**/tmp",
222
- "**/temp",
223
- "**/coverage",
224
- "**/package-lock.json",
225
- "**/yarn.lock",
226
- "**/pnpm-lock.yaml"
227
- ];
228
- if (ignores$ && ignores$.length) {
229
- defaults = defaults.filter((i) => {
230
- if (ignores$.includes(i)) {
231
- return false;
232
- }
233
- const reverse = "!" + i;
234
- if (ignores$.includes(reverse)) {
235
- ignores$ = ignores$?.filter((j) => j !== reverse);
236
- return false;
237
- }
238
- return true;
239
- });
240
- }
241
- return [
242
- {
243
- ignores: [
244
- ...defaults,
245
- ...ignores$
246
- ]
247
- }
248
- ];
167
+ //#endregion
168
+ //#region packages/eslint/src/configs/ignores.ts
169
+ var ignores = async (ignores$ = []) => {
170
+ let defaults = [
171
+ "**/node_modules",
172
+ "**/dist",
173
+ "**/tmp",
174
+ "**/temp",
175
+ "**/coverage",
176
+ "**/package-lock.json",
177
+ "**/yarn.lock",
178
+ "**/pnpm-lock.yaml"
179
+ ];
180
+ if (ignores$ && ignores$.length) defaults = defaults.filter((i) => {
181
+ if (ignores$.includes(i)) return false;
182
+ const reverse = "!" + i;
183
+ if (ignores$.includes(reverse)) {
184
+ ignores$ = ignores$?.filter((j) => j !== reverse);
185
+ return false;
186
+ }
187
+ return true;
188
+ });
189
+ return [{ ignores: [...defaults, ...ignores$] }];
249
190
  };
250
-
251
- const imports = async (options$) => {
252
- const options = await pickOptions("import", options$);
253
- if (!options.enable) {
254
- return [];
255
- }
256
- const recommendedRules = pluginImport.configs.recommended.rules;
257
- const rules = {
258
- ...recommendedRules,
259
- "import-x/newline-after-import": 1,
260
- "import-x/no-unresolved": 0,
261
- "import-x/namespace": 0,
262
- "import-x/default": 0,
263
- "import-x/no-named-as-default": 0,
264
- "import-x/no-named-as-default-member": 0
265
- };
266
- return [
267
- // 单独安装plugins,
268
- {
269
- plugins: {
270
- "import-x": pluginImport
271
- },
272
- settings: {
273
- "import/parsers": {
274
- espree: [".js", ".cjs", ".mjs", ".jsx"]
275
- }
276
- }
277
- },
278
- {
279
- rules: {
280
- ...cleanRules(
281
- "import",
282
- Object.keys(pluginImport.rules).reduce((pre, key) => {
283
- pre[`import-x/${key}`] = 2;
284
- return pre;
285
- }, {}),
286
- recommendedRules,
287
- rules
288
- ),
289
- ...options.overrides
290
- }
291
- }
292
- ];
191
+ //#endregion
192
+ //#region packages/eslint/src/configs/imports.ts
193
+ var imports = async (options$) => {
194
+ const options = await pickOptions("import", options$);
195
+ if (!options.enable) return [];
196
+ const recommendedRules = pluginImport.configs.recommended.rules;
197
+ const rules = {
198
+ ...recommendedRules,
199
+ "import-x/newline-after-import": 1,
200
+ "import-x/no-unresolved": 0,
201
+ "import-x/namespace": 0,
202
+ "import-x/default": 0,
203
+ "import-x/no-named-as-default": 0,
204
+ "import-x/no-named-as-default-member": 0
205
+ };
206
+ return [{
207
+ plugins: { "import-x": pluginImport },
208
+ settings: { "import/parsers": { espree: [
209
+ ".js",
210
+ ".cjs",
211
+ ".mjs",
212
+ ".jsx"
213
+ ] } }
214
+ }, { rules: {
215
+ ...cleanRules("import", Object.keys(pluginImport.rules).reduce((pre, key) => {
216
+ pre[`import-x/${key}`] = 2;
217
+ return pre;
218
+ }, {}), recommendedRules, rules),
219
+ ...options.overrides
220
+ } }];
293
221
  };
294
-
295
- const stylistic = async (options$) => {
296
- const options = await pickOptions("stylistic", options$);
297
- if (!options.enable) {
298
- return [];
299
- }
300
- const config = pluginStylistic.configs.customize({
301
- indent: "tab",
302
- quotes: "single",
303
- semi: true,
304
- jsx: true
305
- });
306
- const allRules = config.rules;
307
- const rules = {
308
- ...allRules,
309
- "@stylistic/comma-dangle": ["warn", {
310
- arrays: "never",
311
- objects: "ignore",
312
- imports: "never",
313
- exports: "never",
314
- functions: "ignore"
315
- }],
316
- "@stylistic/brace-style": ["error", "1tbs", {
317
- allowSingleLine: true
318
- }],
319
- "@stylistic/member-delimiter-style": 1,
320
- "@stylistic/max-statements-per-line": ["off", { max: 1 }],
321
- "@stylistic/max-len": [1, { code: 150 }]
322
- };
323
- return [
324
- // 单独安装plugins, 方便扩展
325
- {
326
- plugins: {
327
- "@stylistic": pluginStylistic
328
- }
329
- },
330
- {
331
- rules: {
332
- ...cleanRules("stylistic", allRules, allRules, rules),
333
- ...options.overrides
334
- }
335
- }
336
- ];
222
+ //#endregion
223
+ //#region packages/eslint/src/configs/stylistic.ts
224
+ var stylistic = async (options$) => {
225
+ const options = await pickOptions("stylistic", options$);
226
+ if (!options.enable) return [];
227
+ const allRules = pluginStylistic.configs.customize({
228
+ indent: "tab",
229
+ quotes: "single",
230
+ semi: true,
231
+ jsx: true
232
+ }).rules;
233
+ const rules = {
234
+ ...allRules,
235
+ "@stylistic/comma-dangle": ["warn", {
236
+ arrays: "never",
237
+ objects: "ignore",
238
+ imports: "never",
239
+ exports: "never",
240
+ functions: "ignore"
241
+ }],
242
+ "@stylistic/brace-style": [
243
+ "error",
244
+ "1tbs",
245
+ { allowSingleLine: true }
246
+ ],
247
+ "@stylistic/member-delimiter-style": 1,
248
+ "@stylistic/max-statements-per-line": ["off", { max: 1 }],
249
+ "@stylistic/max-len": [1, { code: 150 }]
250
+ };
251
+ return [{ plugins: { "@stylistic": pluginStylistic } }, { rules: {
252
+ ...cleanRules("stylistic", allRules, allRules, rules),
253
+ ...options.overrides
254
+ } }];
337
255
  };
338
-
339
- const vue = async (options$) => {
340
- const options = await pickOptions("vue", options$);
341
- if (!options.enable) {
342
- return [];
343
- }
344
- const essentialRules = pluginVue.configs["essential"].rules;
345
- const rules = {
346
- ...essentialRules,
347
- "vue/html-indent": ["error", "tab"],
348
- "vue/no-multiple-template-root": 0,
349
- "vue/multi-word-component-names": 0,
350
- "vue/no-shared-component-data": 0
351
- };
352
- return [
353
- // 单独安装plugins,
354
- {
355
- plugins: {
356
- vue: pluginVue
357
- }
358
- },
359
- ...pluginVue.configs["flat/base"],
360
- {
361
- files: ["**/*.vue"],
362
- languageOptions: {
363
- parser: parserVue,
364
- parserOptions: {
365
- sourceType: "module"
366
- }
367
- },
368
- rules: {
369
- ...cleanRules("vue", essentialRules, essentialRules, rules),
370
- ...options.overrides
371
- }
372
- }
373
- ];
256
+ //#endregion
257
+ //#region packages/eslint/src/configs/vue.ts
258
+ var vue = async (options$) => {
259
+ const options = await pickOptions("vue", options$);
260
+ if (!options.enable) return [];
261
+ const essentialRules = pluginVue.configs["essential"].rules;
262
+ const rules = {
263
+ ...essentialRules,
264
+ "vue/html-indent": ["error", "tab"],
265
+ "vue/no-multiple-template-root": 0,
266
+ "vue/multi-word-component-names": 0,
267
+ "vue/no-shared-component-data": 0
268
+ };
269
+ return [
270
+ { plugins: { vue: pluginVue } },
271
+ ...pluginVue.configs["flat/base"],
272
+ {
273
+ files: ["**/*.vue"],
274
+ languageOptions: {
275
+ parser: parserVue,
276
+ parserOptions: { sourceType: "module" }
277
+ },
278
+ rules: {
279
+ ...cleanRules("vue", essentialRules, essentialRules, rules),
280
+ ...options.overrides
281
+ }
282
+ }
283
+ ];
374
284
  };
375
-
376
- const configure = async (options, ...userConfigs) => {
377
- const configs = [
378
- ...await ignores(options?.ignores),
379
- ...await javascript(options),
380
- ...await typescript(options),
381
- ...await jsdoc(options),
382
- ...await markdown(options),
383
- ...await imports(options),
384
- ...await stylistic(options),
385
- ...await vue(options)
386
- ];
387
- return configs.concat(userConfigs);
285
+ //#endregion
286
+ //#region packages/eslint/src/configure.ts
287
+ var configure = async (options, ...userConfigs) => {
288
+ return [
289
+ ...await ignores(options?.ignores),
290
+ ...await javascript(options),
291
+ ...await typescript(options),
292
+ ...await jsdoc(options),
293
+ ...await markdown(options),
294
+ ...await imports(options),
295
+ ...await stylistic(options),
296
+ ...await vue(options)
297
+ ].concat(userConfigs);
388
298
  };
389
-
390
- const index = configure();
391
-
392
- export { configure, index as default };
299
+ //#endregion
300
+ //#region packages/eslint/src/index.ts
301
+ var src_default = configure();
302
+ //#endregion
303
+ export { configure, src_default as default };