@cuiqg/eslint-config 2.8.4 → 2.8.6

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.
Files changed (3) hide show
  1. package/README.md +14 -3
  2. package/dist/index.mjs +267 -62
  3. package/package.json +9 -8
package/README.md CHANGED
@@ -13,17 +13,26 @@ npm i -D eslint @cuiqg/eslint-config
13
13
  + "type": "module",
14
14
  "scripts": {
15
15
  + "lint": "eslint .",
16
- + "lint:fix": "eslint . --fix"
16
+ + "lint:fix": "eslint . --fix",
17
+ + "lint:inspect": "eslint . --inspect-config"
17
18
  }
18
19
  }
19
20
  ```
20
21
 
21
- 创建 `eslint.config.js` 文件
22
+ 创建 `eslint.config.mjs` 文件
22
23
 
23
24
  ```js
25
+ import fs from 'node:fs'
24
26
  import cuiqg from '@cuiqg/eslint-config'
27
+ import { FlatCompat } from '@eslint/eslintrc'
25
28
 
26
- export default cuiqg()
29
+ const compat = new FlatCompat()
30
+
31
+ export default cuiqg({},
32
+ fs.existsSync('.eslintrc-auto-import.json')
33
+ ? compat.extend('./.eslintrc-auto-import.json')
34
+ : []
35
+ )
27
36
  ```
28
37
 
29
38
  ## 插件配置
@@ -36,7 +45,9 @@ export default cuiqg()
36
45
  {
37
46
  "prettier.enable": false,
38
47
  "editor.formatOnSave": false,
48
+
39
49
  "eslint.useFlatConfig": true,
50
+
40
51
  "editor.codeActionsOnSave": {
41
52
  "source.fixAll.eslint": "explicit",
42
53
  "source.organizeImports": "never"
package/dist/index.mjs CHANGED
@@ -17,18 +17,7 @@ const GLOB_SCSS = "**/*.scss";
17
17
  const GLOB_LESS = "**/*.less";
18
18
  const GLOB_STYLUS = "**/*.styl";
19
19
  const GLOB_POSTCSS = "**/*.{p,post}css";
20
- const GLOB_JSON = "**/*.json";
21
- const GLOB_JSON5 = "**/*.json5";
22
- const GLOB_JSONC = "**/*.jsonc";
23
- const GLOB_MARKDOWN = "**/*.md";
24
20
  const GLOB_VUE = "**/*.vue";
25
- const GLOB_YAML = "**/*.y?(a)ml";
26
- const GLOB_TOML = "**/*.toml";
27
- const GLOB_XML = "**/*.xml";
28
- const GLOB_SVG = "**/*.svg";
29
- const GLOB_HTML = "**/*.htm?(l)";
30
- const GLOB_GRAPHQL = "**/*.{g,graph}ql";
31
- const GLOB_PHP = "**/*.php";
32
21
  const GLOB_EXCLUDE = [
33
22
  "**/node_modules",
34
23
  "**/dist",
@@ -101,11 +90,36 @@ async function ignores() {
101
90
  })];
102
91
  }
103
92
 
93
+ //#endregion
94
+ //#region src/env.js
95
+ const isInGitHookOrLintStaged = () => {
96
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
97
+ };
98
+ const isInEditor = () => {
99
+ if (process.env.CI) return false;
100
+ if (isInGitHookOrLintStaged()) return false;
101
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
102
+ };
103
+ const hasVue = () => [
104
+ "vue",
105
+ "nuxt",
106
+ "vitepress",
107
+ "@slidev/cli"
108
+ ].some((i) => isPackageExists(i));
109
+ const hasTypeScript = () => isPackageExists("typescript");
110
+ const hasUnocss = () => isPackageExists("unocss");
111
+ const hasTailwindcss = () => isPackageExists("tailwindcss");
112
+ const hasPrettier = () => isPackageExists("prettier");
113
+
104
114
  //#endregion
105
115
  //#region src/configs/javascript.js
106
116
  async function javascript() {
107
- const [pluginJs] = await Promise.all([interopDefault(import("@eslint/js"))]);
117
+ const files = [GLOB_SRC];
118
+ const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports"));
108
119
  return [{
120
+ files,
121
+ name: "cuiqg/javascript",
122
+ plugins: { "unused-imports": pluginUnusedImports },
109
123
  languageOptions: {
110
124
  ecmaVersion: "latest",
111
125
  globals: {
@@ -121,16 +135,195 @@ async function javascript() {
121
135
  sourceType: "module"
122
136
  },
123
137
  linterOptions: { reportUnusedDisableDirectives: true },
124
- name: "cuiqg/javascript",
125
- plugins: { js: pluginJs },
126
138
  rules: {
127
- ...pluginJs.configs.recommended.rules,
139
+ "accessor-pairs": ["error", {
140
+ enforceForClassMembers: true,
141
+ setWithoutGet: true
142
+ }],
143
+ "array-callback-return": "error",
144
+ "block-scoped-var": "error",
145
+ "constructor-super": "error",
146
+ "default-case-last": "error",
147
+ "dot-notation": ["error", { allowKeywords: true }],
148
+ "eqeqeq": ["error", "smart"],
149
+ "new-cap": ["error", {
150
+ capIsNew: false,
151
+ newIsCap: true,
152
+ properties: true
153
+ }],
154
+ "no-alert": "error",
155
+ "no-array-constructor": "error",
156
+ "no-async-promise-executor": "error",
157
+ "no-caller": "error",
158
+ "no-case-declarations": "error",
159
+ "no-class-assign": "error",
160
+ "no-compare-neg-zero": "error",
161
+ "no-cond-assign": ["error", "always"],
162
+ "no-console": ["error", { allow: ["warn", "error"] }],
163
+ "no-const-assign": "error",
164
+ "no-control-regex": "error",
165
+ "no-debugger": "error",
166
+ "no-delete-var": "error",
167
+ "no-dupe-args": "error",
168
+ "no-dupe-class-members": "error",
169
+ "no-dupe-keys": "error",
170
+ "no-duplicate-case": "error",
171
+ "no-empty": ["error", { allowEmptyCatch: true }],
172
+ "no-empty-character-class": "error",
173
+ "no-empty-pattern": "error",
174
+ "no-eval": "error",
175
+ "no-ex-assign": "error",
176
+ "no-extend-native": "error",
177
+ "no-extra-bind": "error",
178
+ "no-extra-boolean-cast": "error",
179
+ "no-fallthrough": "error",
180
+ "no-func-assign": "error",
181
+ "no-global-assign": "error",
182
+ "no-implied-eval": "error",
183
+ "no-import-assign": "error",
184
+ "no-invalid-regexp": "error",
185
+ "no-irregular-whitespace": "error",
186
+ "no-iterator": "error",
187
+ "no-labels": ["error", {
188
+ allowLoop: false,
189
+ allowSwitch: false
190
+ }],
191
+ "no-lone-blocks": "error",
192
+ "no-loss-of-precision": "error",
193
+ "no-misleading-character-class": "error",
194
+ "no-multi-str": "error",
195
+ "no-new": "error",
196
+ "no-new-func": "error",
197
+ "no-new-native-nonconstructor": "error",
198
+ "no-new-wrappers": "error",
199
+ "no-obj-calls": "error",
200
+ "no-octal": "error",
201
+ "no-octal-escape": "error",
202
+ "no-proto": "error",
203
+ "no-prototype-builtins": "error",
204
+ "no-redeclare": ["error", { builtinGlobals: false }],
205
+ "no-regex-spaces": "error",
206
+ "no-restricted-globals": [
207
+ "error",
208
+ {
209
+ message: "Use `globalThis` instead.",
210
+ name: "global"
211
+ },
212
+ {
213
+ message: "Use `globalThis` instead.",
214
+ name: "self"
215
+ }
216
+ ],
217
+ "no-restricted-properties": [
218
+ "error",
219
+ {
220
+ message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
221
+ property: "__proto__"
222
+ },
223
+ {
224
+ message: "Use `Object.defineProperty` instead.",
225
+ property: "__defineGetter__"
226
+ },
227
+ {
228
+ message: "Use `Object.defineProperty` instead.",
229
+ property: "__defineSetter__"
230
+ },
231
+ {
232
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
233
+ property: "__lookupGetter__"
234
+ },
235
+ {
236
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
237
+ property: "__lookupSetter__"
238
+ }
239
+ ],
240
+ "no-restricted-syntax": [
241
+ "error",
242
+ "TSEnumDeclaration[const=true]",
243
+ "TSExportAssignment"
244
+ ],
245
+ "no-self-assign": ["error", { props: true }],
246
+ "no-self-compare": "error",
247
+ "no-sequences": "error",
248
+ "no-shadow-restricted-names": "error",
249
+ "no-sparse-arrays": "error",
250
+ "no-template-curly-in-string": "error",
251
+ "no-this-before-super": "error",
252
+ "no-throw-literal": "error",
253
+ "no-undef": "error",
254
+ "no-undef-init": "error",
255
+ "no-unexpected-multiline": "error",
256
+ "no-unmodified-loop-condition": "error",
257
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
258
+ "no-unreachable": "error",
259
+ "no-unreachable-loop": "error",
260
+ "no-unsafe-finally": "error",
261
+ "no-unsafe-negation": "error",
262
+ "no-unused-expressions": ["error", {
263
+ allowShortCircuit: true,
264
+ allowTaggedTemplates: true,
265
+ allowTernary: true
266
+ }],
128
267
  "no-unused-vars": ["error", {
268
+ args: "none",
269
+ caughtErrors: "none",
270
+ ignoreRestSiblings: true,
271
+ vars: "all"
272
+ }],
273
+ "no-use-before-define": ["error", {
274
+ classes: false,
275
+ functions: false,
276
+ variables: true
277
+ }],
278
+ "no-useless-backreference": "error",
279
+ "no-useless-call": "error",
280
+ "no-useless-catch": "error",
281
+ "no-useless-computed-key": "error",
282
+ "no-useless-constructor": "error",
283
+ "no-useless-rename": "error",
284
+ "no-useless-return": "error",
285
+ "no-var": "error",
286
+ "no-with": "error",
287
+ "object-shorthand": [
288
+ "error",
289
+ "always",
290
+ {
291
+ avoidQuotes: true,
292
+ ignoreConstructors: false
293
+ }
294
+ ],
295
+ "one-var": ["error", { initialized: "never" }],
296
+ "prefer-arrow-callback": ["error", {
297
+ allowNamedFunctions: false,
298
+ allowUnboundThis: true
299
+ }],
300
+ "prefer-const": [isInEditor ? "warn" : "error", {
301
+ destructuring: "all",
302
+ ignoreReadBeforeAssign: true
303
+ }],
304
+ "prefer-exponentiation-operator": "error",
305
+ "prefer-promise-reject-errors": "error",
306
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
307
+ "prefer-rest-params": "error",
308
+ "prefer-spread": "error",
309
+ "prefer-template": "error",
310
+ "symbol-description": "error",
311
+ "unicode-bom": ["error", "never"],
312
+ "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
313
+ "unused-imports/no-unused-vars": ["error", {
314
+ args: "after-used",
129
315
  argsIgnorePattern: "^_",
130
- caughtErrorsIgnorePattern: "^_",
131
316
  ignoreRestSiblings: true,
317
+ vars: "all",
132
318
  varsIgnorePattern: "^_"
133
- }]
319
+ }],
320
+ "use-isnan": ["error", {
321
+ enforceForIndexOf: true,
322
+ enforceForSwitchCase: true
323
+ }],
324
+ "valid-typeof": ["error", { requireStringLiterals: true }],
325
+ "vars-on-top": "error",
326
+ "yoda": ["error", "never"]
134
327
  }
135
328
  }];
136
329
  }
@@ -175,14 +368,52 @@ async function macros() {
175
368
  //#endregion
176
369
  //#region src/configs/package-json.js
177
370
  async function packageJson() {
178
- const pluginPackageJson = await interopDefault(import("eslint-plugin-package-json"));
371
+ const [pluginPackageJson, pluginDepend, parserJsonc] = await Promise.all([
372
+ interopDefault(import("eslint-plugin-package-json")),
373
+ interopDefault(import("eslint-plugin-depend")),
374
+ interopDefault(import("jsonc-eslint-parser"))
375
+ ]);
179
376
  return [{
180
- ...pluginPackageJson.configs.recommended,
181
- rules: {
182
- ...pluginPackageJson.configs.recommended.rules,
183
- ...pluginPackageJson.configs.stylistic.rules
377
+ name: "cuiqg/package-json",
378
+ files: ["**/package.json"],
379
+ plugins: {
380
+ "package-json": pluginPackageJson,
381
+ "depend": pluginDepend
184
382
  },
185
- name: "cuiqg/package-json"
383
+ languageOptions: { parser: parserJsonc },
384
+ rules: {
385
+ "depend/ban-dependencies": "error",
386
+ "package-json/bin-name-casing": "error",
387
+ "package-json/exports-subpaths-style": ["error", { prefer: "explicit" }],
388
+ "package-json/no-empty-fields": "error",
389
+ "package-json/no-redundant-files": "error",
390
+ "package-json/no-redundant-publishConfig": "error",
391
+ "package-json/order-properties": ["error", { order: "sort-package-json" }],
392
+ "package-json/repository-shorthand": ["error", { form: "shorthand" }],
393
+ "package-json/require-author": "error",
394
+ "package-json/require-description": "error",
395
+ "package-json/require-engines": "error",
396
+ "package-json/require-keywords": "error",
397
+ "package-json/require-name": "error",
398
+ "package-json/require-type": "error",
399
+ "package-json/require-version": "error",
400
+ "package-json/scripts-name-casing": "error",
401
+ "package-json/sort-collections": "error",
402
+ "package-json/specify-peers-locally": "error",
403
+ "package-json/unique-dependencies": "error",
404
+ "package-json/valid-author": "error",
405
+ "package-json/valid-bin": "error",
406
+ "package-json/valid-dependencies": "error",
407
+ "package-json/valid-description": "error",
408
+ "package-json/valid-directories": "error",
409
+ "package-json/valid-files": "error",
410
+ "package-json/valid-homepage": "error",
411
+ "package-json/valid-keywords": "error",
412
+ "package-json/valid-license": "error",
413
+ "package-json/valid-name": "error",
414
+ "package-json/valid-scripts": "error",
415
+ "package-json/valid-version": "error"
416
+ }
186
417
  }];
187
418
  }
188
419
 
@@ -393,45 +624,21 @@ async function tailwindcss() {
393
624
  }
394
625
 
395
626
  //#endregion
396
- //#region src/configs/imports.js
397
- async function imports() {
398
- const pluginImportX = await interopDefault(import("eslint-plugin-import-x"));
627
+ //#region src/configs/comments.js
628
+ async function comments() {
629
+ const pluginComments = await interopDefault(import("@eslint-community/eslint-plugin-eslint-comments"));
399
630
  return [{
400
- name: "cuiqg/imports",
401
- plugins: { "import-x": pluginImportX },
631
+ name: "cuiqg/eslint-comments",
632
+ plugins: { "@eslint-community/eslint-comments": pluginComments },
402
633
  rules: {
403
- "import-x/consistent-type-specifier-style": ["error", "prefer-top-level"],
404
- "import-x/first": "error",
405
- "import-x/no-duplicates": "error",
406
- "import-x/no-mutable-exports": "error",
407
- "import-x/no-named-default": "error",
408
- "import-x/newline-after-import": ["error", { "count": 1 }]
409
- },
410
- settings: { "import-x/core-modules": ["electron", "vue-router/auto-routes"] }
634
+ "@eslint-community/eslint-comments/no-aggregating-enable": "error",
635
+ "@eslint-community/eslint-comments/no-duplicate-disable": "error",
636
+ "@eslint-community/eslint-comments/no-unlimited-disable": "error",
637
+ "@eslint-community/eslint-comments/no-unused-enable": "error"
638
+ }
411
639
  }];
412
640
  }
413
641
 
414
- //#endregion
415
- //#region src/env.js
416
- const isInGitHookOrLintStaged = () => {
417
- return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
418
- };
419
- const isInEditor = () => {
420
- if (process.env.CI) return false;
421
- if (isInGitHookOrLintStaged()) return false;
422
- return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
423
- };
424
- const hasVue = () => [
425
- "vue",
426
- "nuxt",
427
- "vitepress",
428
- "@slidev/cli"
429
- ].some((i) => isPackageExists(i));
430
- const hasTypeScript = () => isPackageExists("typescript");
431
- const hasUnocss = () => isPackageExists("unocss");
432
- const hasTailwindcss = () => isPackageExists("tailwindcss");
433
- const hasPrettier = () => isPackageExists("prettier");
434
-
435
642
  //#endregion
436
643
  //#region src/presets.js
437
644
  const defaultPluginRenaming = {};
@@ -442,18 +649,16 @@ const defaultPluginRenaming = {};
442
649
  * @param {boolean} [options.unocss] - 是否启用 Unocss 格式化
443
650
  * @param {boolean} [options.tailwindcss] - 是否启用 Tailwindcss 格式化
444
651
  * @param {boolean} [options.vue] - 是否启用 VUE 格式化
445
- * @param {boolean} [options.imports=true] - 是否启用 Import-X
446
652
  * @param {boolean} [options.jsdoc=true] - 是否启用 JSDoc 格式化
447
653
  * @param {...Object} userConfigs - 用户配置
448
654
  *
449
655
  * @returns {Promise<Object[]>} 合并后的配置
450
656
  */
451
657
  function cuiqg(options = {}, ...userConfigs) {
452
- const { jsdoc: enableJsdoc = true, prettier: enablePrettier = hasPrettier(), unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue(), imports: enableImports = true } = options;
658
+ const { jsdoc: enableJsdoc = true, prettier: enablePrettier = hasPrettier(), unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue() } = options;
453
659
  const configs = [];
454
- configs.push(ignores(), javascript(), stylistic(), packageJson());
660
+ configs.push(ignores(), comments(), javascript(), stylistic(), packageJson());
455
661
  if (enableJsdoc) configs.push(jsdoc());
456
- if (enableImports) configs.push(imports());
457
662
  if (enableVue) configs.push(vue(), macros());
458
663
  if (enableUnocss) configs.push(unocss());
459
664
  if (enableTailwindcss) configs.push(tailwindcss());
@@ -468,4 +673,4 @@ function cuiqg(options = {}, ...userConfigs) {
468
673
  var src_default = cuiqg;
469
674
 
470
675
  //#endregion
471
- export { GLOB_CSS, GLOB_EXCLUDE, GLOB_GRAPHQL, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_PHP, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_STYLUS, GLOB_SVG, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, cuiqg, src_default as default, defaultPluginRenaming, hasPrettier, hasTailwindcss, hasTypeScript, hasUnocss, hasVue, ignores, imports, isInEditor, isInGitHookOrLintStaged, javascript, jsdoc, macros, packageJson, prettier, stylistic, stylisticConfigDefaults, tailwindcss, unocss, vue };
676
+ export { GLOB_CSS, GLOB_EXCLUDE, GLOB_JS, GLOB_JSX, GLOB_LESS, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_STYLUS, GLOB_TS, GLOB_TSX, GLOB_VUE, comments, cuiqg, src_default as default, defaultPluginRenaming, hasPrettier, hasTailwindcss, hasTypeScript, hasUnocss, hasVue, ignores, isInEditor, isInGitHookOrLintStaged, javascript, jsdoc, macros, packageJson, prettier, stylistic, stylisticConfigDefaults, tailwindcss, unocss, vue };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuiqg/eslint-config",
3
- "version": "2.8.4",
3
+ "version": "2.8.6",
4
4
  "description": "Eslint config for @cuiqg",
5
5
  "keywords": [
6
6
  "eslint-config"
@@ -36,29 +36,30 @@
36
36
  "@eslint/config-inspector": "^1.4.2",
37
37
  "@eslint/eslintrc": "^3.3.3",
38
38
  "bumpp": "^10.3.2",
39
- "eslint": "^9.39.1",
40
- "tsdown": "^0.16.8"
39
+ "eslint": "^9.39.2",
40
+ "tsdown": "^0.18.2"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "eslint": ">=9.28.0"
44
44
  },
45
45
  "dependencies": {
46
- "@eslint/js": "^9.39.1",
46
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
47
47
  "@stylistic/eslint-plugin": "^5.6.1",
48
- "@unocss/eslint-plugin": "^66.5.9",
48
+ "@unocss/eslint-plugin": "^66.5.10",
49
49
  "@vue-macros/eslint-config": "3.0.0-beta.21",
50
50
  "eslint-config-flat-gitignore": "^2.1.0",
51
51
  "eslint-config-prettier": "^10.1.8",
52
52
  "eslint-flat-config-utils": "^2.1.4",
53
- "eslint-plugin-format": "^1.0.2",
53
+ "eslint-plugin-depend": "^1.4.0",
54
54
  "eslint-plugin-import-x": "^4.16.1",
55
- "eslint-plugin-jsdoc": "^61.4.1",
55
+ "eslint-plugin-jsdoc": "^61.5.0",
56
56
  "eslint-plugin-package-json": "^0.85.0",
57
57
  "eslint-plugin-prettier": "^5.5.4",
58
58
  "eslint-plugin-tailwindcss": "4.0.0-beta.0",
59
+ "eslint-plugin-unused-imports": "^4.3.0",
59
60
  "eslint-plugin-vue": "^10.6.2",
60
61
  "globals": "^16.5.0",
61
- "jsonc-eslint-parser": "^2.4.1",
62
+ "jsonc-eslint-parser": "^2.4.2",
62
63
  "local-pkg": "^1.1.2",
63
64
  "vue-eslint-parser": "^10.2.0"
64
65
  }