@cuiqg/eslint-config 2.8.5 → 2.8.7

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 (2) hide show
  1. package/dist/index.mjs +267 -63
  2. package/package.json +4 -3
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,35 @@ 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
+
104
113
  //#endregion
105
114
  //#region src/configs/javascript.js
106
115
  async function javascript() {
107
- const [pluginJs] = await Promise.all([interopDefault(import("@eslint/js"))]);
116
+ const files = [GLOB_SRC];
117
+ const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports"));
108
118
  return [{
119
+ files,
120
+ name: "cuiqg/javascript",
121
+ plugins: { "unused-imports": pluginUnusedImports },
109
122
  languageOptions: {
110
123
  ecmaVersion: "latest",
111
124
  globals: {
@@ -121,16 +134,195 @@ async function javascript() {
121
134
  sourceType: "module"
122
135
  },
123
136
  linterOptions: { reportUnusedDisableDirectives: true },
124
- name: "cuiqg/javascript",
125
- plugins: { js: pluginJs },
126
137
  rules: {
127
- ...pluginJs.configs.recommended.rules,
138
+ "accessor-pairs": ["error", {
139
+ enforceForClassMembers: true,
140
+ setWithoutGet: true
141
+ }],
142
+ "array-callback-return": "error",
143
+ "block-scoped-var": "error",
144
+ "constructor-super": "error",
145
+ "default-case-last": "error",
146
+ "dot-notation": ["error", { allowKeywords: true }],
147
+ "eqeqeq": ["error", "smart"],
148
+ "new-cap": ["error", {
149
+ capIsNew: false,
150
+ newIsCap: true,
151
+ properties: true
152
+ }],
153
+ "no-alert": "error",
154
+ "no-array-constructor": "error",
155
+ "no-async-promise-executor": "error",
156
+ "no-caller": "error",
157
+ "no-case-declarations": "error",
158
+ "no-class-assign": "error",
159
+ "no-compare-neg-zero": "error",
160
+ "no-cond-assign": ["error", "always"],
161
+ "no-console": ["error", { allow: ["warn", "error"] }],
162
+ "no-const-assign": "error",
163
+ "no-control-regex": "error",
164
+ "no-debugger": "error",
165
+ "no-delete-var": "error",
166
+ "no-dupe-args": "error",
167
+ "no-dupe-class-members": "error",
168
+ "no-dupe-keys": "error",
169
+ "no-duplicate-case": "error",
170
+ "no-empty": ["error", { allowEmptyCatch: true }],
171
+ "no-empty-character-class": "error",
172
+ "no-empty-pattern": "error",
173
+ "no-eval": "error",
174
+ "no-ex-assign": "error",
175
+ "no-extend-native": "error",
176
+ "no-extra-bind": "error",
177
+ "no-extra-boolean-cast": "error",
178
+ "no-fallthrough": "error",
179
+ "no-func-assign": "error",
180
+ "no-global-assign": "error",
181
+ "no-implied-eval": "error",
182
+ "no-import-assign": "error",
183
+ "no-invalid-regexp": "error",
184
+ "no-irregular-whitespace": "error",
185
+ "no-iterator": "error",
186
+ "no-labels": ["error", {
187
+ allowLoop: false,
188
+ allowSwitch: false
189
+ }],
190
+ "no-lone-blocks": "error",
191
+ "no-loss-of-precision": "error",
192
+ "no-misleading-character-class": "error",
193
+ "no-multi-str": "error",
194
+ "no-new": "error",
195
+ "no-new-func": "error",
196
+ "no-new-native-nonconstructor": "error",
197
+ "no-new-wrappers": "error",
198
+ "no-obj-calls": "error",
199
+ "no-octal": "error",
200
+ "no-octal-escape": "error",
201
+ "no-proto": "error",
202
+ "no-prototype-builtins": "error",
203
+ "no-redeclare": ["error", { builtinGlobals: false }],
204
+ "no-regex-spaces": "error",
205
+ "no-restricted-globals": [
206
+ "error",
207
+ {
208
+ message: "Use `globalThis` instead.",
209
+ name: "global"
210
+ },
211
+ {
212
+ message: "Use `globalThis` instead.",
213
+ name: "self"
214
+ }
215
+ ],
216
+ "no-restricted-properties": [
217
+ "error",
218
+ {
219
+ message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
220
+ property: "__proto__"
221
+ },
222
+ {
223
+ message: "Use `Object.defineProperty` instead.",
224
+ property: "__defineGetter__"
225
+ },
226
+ {
227
+ message: "Use `Object.defineProperty` instead.",
228
+ property: "__defineSetter__"
229
+ },
230
+ {
231
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
232
+ property: "__lookupGetter__"
233
+ },
234
+ {
235
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
236
+ property: "__lookupSetter__"
237
+ }
238
+ ],
239
+ "no-restricted-syntax": [
240
+ "error",
241
+ "TSEnumDeclaration[const=true]",
242
+ "TSExportAssignment"
243
+ ],
244
+ "no-self-assign": ["error", { props: true }],
245
+ "no-self-compare": "error",
246
+ "no-sequences": "error",
247
+ "no-shadow-restricted-names": "error",
248
+ "no-sparse-arrays": "error",
249
+ "no-template-curly-in-string": "error",
250
+ "no-this-before-super": "error",
251
+ "no-throw-literal": "error",
252
+ "no-undef": "error",
253
+ "no-undef-init": "error",
254
+ "no-unexpected-multiline": "error",
255
+ "no-unmodified-loop-condition": "error",
256
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
257
+ "no-unreachable": "error",
258
+ "no-unreachable-loop": "error",
259
+ "no-unsafe-finally": "error",
260
+ "no-unsafe-negation": "error",
261
+ "no-unused-expressions": ["error", {
262
+ allowShortCircuit: true,
263
+ allowTaggedTemplates: true,
264
+ allowTernary: true
265
+ }],
128
266
  "no-unused-vars": ["error", {
267
+ args: "none",
268
+ caughtErrors: "none",
269
+ ignoreRestSiblings: true,
270
+ vars: "all"
271
+ }],
272
+ "no-use-before-define": ["error", {
273
+ classes: false,
274
+ functions: false,
275
+ variables: true
276
+ }],
277
+ "no-useless-backreference": "error",
278
+ "no-useless-call": "error",
279
+ "no-useless-catch": "error",
280
+ "no-useless-computed-key": "error",
281
+ "no-useless-constructor": "error",
282
+ "no-useless-rename": "error",
283
+ "no-useless-return": "error",
284
+ "no-var": "error",
285
+ "no-with": "error",
286
+ "object-shorthand": [
287
+ "error",
288
+ "always",
289
+ {
290
+ avoidQuotes: true,
291
+ ignoreConstructors: false
292
+ }
293
+ ],
294
+ "one-var": ["error", { initialized: "never" }],
295
+ "prefer-arrow-callback": ["error", {
296
+ allowNamedFunctions: false,
297
+ allowUnboundThis: true
298
+ }],
299
+ "prefer-const": [isInEditor ? "warn" : "error", {
300
+ destructuring: "all",
301
+ ignoreReadBeforeAssign: true
302
+ }],
303
+ "prefer-exponentiation-operator": "error",
304
+ "prefer-promise-reject-errors": "error",
305
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
306
+ "prefer-rest-params": "error",
307
+ "prefer-spread": "error",
308
+ "prefer-template": "error",
309
+ "symbol-description": "error",
310
+ "unicode-bom": ["error", "never"],
311
+ "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
312
+ "unused-imports/no-unused-vars": ["error", {
313
+ args: "after-used",
129
314
  argsIgnorePattern: "^_",
130
- caughtErrorsIgnorePattern: "^_",
131
315
  ignoreRestSiblings: true,
316
+ vars: "all",
132
317
  varsIgnorePattern: "^_"
133
- }]
318
+ }],
319
+ "use-isnan": ["error", {
320
+ enforceForIndexOf: true,
321
+ enforceForSwitchCase: true
322
+ }],
323
+ "valid-typeof": ["error", { requireStringLiterals: true }],
324
+ "vars-on-top": "error",
325
+ "yoda": ["error", "never"]
134
326
  }
135
327
  }];
136
328
  }
@@ -175,14 +367,52 @@ async function macros() {
175
367
  //#endregion
176
368
  //#region src/configs/package-json.js
177
369
  async function packageJson() {
178
- const pluginPackageJson = await interopDefault(import("eslint-plugin-package-json"));
370
+ const [pluginPackageJson, pluginDepend, parserJsonc] = await Promise.all([
371
+ interopDefault(import("eslint-plugin-package-json")),
372
+ interopDefault(import("eslint-plugin-depend")),
373
+ interopDefault(import("jsonc-eslint-parser"))
374
+ ]);
179
375
  return [{
180
- ...pluginPackageJson.configs.recommended,
181
- rules: {
182
- ...pluginPackageJson.configs.recommended.rules,
183
- ...pluginPackageJson.configs.stylistic.rules
376
+ name: "cuiqg/package-json",
377
+ files: ["**/package.json"],
378
+ plugins: {
379
+ "package-json": pluginPackageJson,
380
+ "depend": pluginDepend
184
381
  },
185
- name: "cuiqg/package-json"
382
+ languageOptions: { parser: parserJsonc },
383
+ rules: {
384
+ "depend/ban-dependencies": "error",
385
+ "package-json/bin-name-casing": "error",
386
+ "package-json/exports-subpaths-style": ["error", { prefer: "explicit" }],
387
+ "package-json/no-empty-fields": "error",
388
+ "package-json/no-redundant-files": "error",
389
+ "package-json/no-redundant-publishConfig": "error",
390
+ "package-json/order-properties": ["error", { order: "sort-package-json" }],
391
+ "package-json/repository-shorthand": ["error", { form: "shorthand" }],
392
+ "package-json/require-author": "error",
393
+ "package-json/require-description": "error",
394
+ "package-json/require-engines": "error",
395
+ "package-json/require-keywords": "error",
396
+ "package-json/require-name": "error",
397
+ "package-json/require-type": "error",
398
+ "package-json/require-version": "error",
399
+ "package-json/scripts-name-casing": "error",
400
+ "package-json/sort-collections": "error",
401
+ "package-json/specify-peers-locally": "error",
402
+ "package-json/unique-dependencies": "error",
403
+ "package-json/valid-author": "error",
404
+ "package-json/valid-bin": "error",
405
+ "package-json/valid-dependencies": "error",
406
+ "package-json/valid-description": "error",
407
+ "package-json/valid-directories": "error",
408
+ "package-json/valid-files": "error",
409
+ "package-json/valid-homepage": "error",
410
+ "package-json/valid-keywords": "error",
411
+ "package-json/valid-license": "error",
412
+ "package-json/valid-name": "error",
413
+ "package-json/valid-scripts": "error",
414
+ "package-json/valid-version": "error"
415
+ }
186
416
  }];
187
417
  }
188
418
 
@@ -393,67 +623,41 @@ async function tailwindcss() {
393
623
  }
394
624
 
395
625
  //#endregion
396
- //#region src/configs/imports.js
397
- async function imports() {
398
- const pluginImportX = await interopDefault(import("eslint-plugin-import-x"));
626
+ //#region src/configs/comments.js
627
+ async function comments() {
628
+ const pluginComments = await interopDefault(import("@eslint-community/eslint-plugin-eslint-comments"));
399
629
  return [{
400
- name: "cuiqg/imports",
401
- plugins: { "import-x": pluginImportX },
630
+ name: "cuiqg/eslint-comments",
631
+ plugins: { "@eslint-community/eslint-comments": pluginComments },
402
632
  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"] }
633
+ "@eslint-community/eslint-comments/no-aggregating-enable": "error",
634
+ "@eslint-community/eslint-comments/no-duplicate-disable": "error",
635
+ "@eslint-community/eslint-comments/no-unlimited-disable": "error",
636
+ "@eslint-community/eslint-comments/no-unused-enable": "error"
637
+ }
411
638
  }];
412
639
  }
413
640
 
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
641
  //#endregion
436
642
  //#region src/presets.js
437
643
  const defaultPluginRenaming = {};
438
644
  /**
439
645
  *
440
646
  * @param {object} options - 设置选项
441
- * @param {boolean} [options.prettier] - 是否启用 Prettier 格式化
647
+ * @param {boolean} [options.prettier=false] - 是否启用 Prettier 格式化
442
648
  * @param {boolean} [options.unocss] - 是否启用 Unocss 格式化
443
649
  * @param {boolean} [options.tailwindcss] - 是否启用 Tailwindcss 格式化
444
650
  * @param {boolean} [options.vue] - 是否启用 VUE 格式化
445
- * @param {boolean} [options.imports=true] - 是否启用 Import-X
446
651
  * @param {boolean} [options.jsdoc=true] - 是否启用 JSDoc 格式化
447
652
  * @param {...Object} userConfigs - 用户配置
448
653
  *
449
654
  * @returns {Promise<Object[]>} 合并后的配置
450
655
  */
451
656
  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;
657
+ const { jsdoc: enableJsdoc = true, prettier: enablePrettier = false, unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue() } = options;
453
658
  const configs = [];
454
- configs.push(ignores(), javascript(), stylistic(), packageJson());
659
+ configs.push(ignores(), comments(), javascript(), stylistic(), packageJson());
455
660
  if (enableJsdoc) configs.push(jsdoc());
456
- if (enableImports) configs.push(imports());
457
661
  if (enableVue) configs.push(vue(), macros());
458
662
  if (enableUnocss) configs.push(unocss());
459
663
  if (enableTailwindcss) configs.push(tailwindcss());
@@ -468,4 +672,4 @@ function cuiqg(options = {}, ...userConfigs) {
468
672
  var src_default = cuiqg;
469
673
 
470
674
  //#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 };
675
+ 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, 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.5",
3
+ "version": "2.8.7",
4
4
  "description": "Eslint config for @cuiqg",
5
5
  "keywords": [
6
6
  "eslint-config"
@@ -43,19 +43,20 @@
43
43
  "eslint": ">=9.28.0"
44
44
  },
45
45
  "dependencies": {
46
- "@eslint/js": "^9.39.2",
46
+ "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
47
47
  "@stylistic/eslint-plugin": "^5.6.1",
48
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.1.0",
53
+ "eslint-plugin-depend": "^1.4.0",
54
54
  "eslint-plugin-import-x": "^4.16.1",
55
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
62
  "jsonc-eslint-parser": "^2.4.2",