@cuiqg/eslint-config 2.8.2 → 2.8.4

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 +46 -152
  2. package/package.json +12 -12
package/dist/index.mjs CHANGED
@@ -73,25 +73,6 @@ const GLOB_EXCLUDE = [
73
73
  //#endregion
74
74
  //#region src/utils.js
75
75
  const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
76
- const parserPlain = {
77
- meta: { name: "parser-plain" },
78
- parseForESLint: (code) => ({
79
- ast: {
80
- body: [],
81
- comments: [],
82
- loc: {
83
- end: code.length,
84
- start: 0
85
- },
86
- range: [0, code.length],
87
- tokens: [],
88
- type: "Program"
89
- },
90
- scopeManager: null,
91
- services: { isPlain: true },
92
- visitorKeys: { Program: [] }
93
- })
94
- };
95
76
  async function interopDefault(module) {
96
77
  try {
97
78
  let resolved = await module;
@@ -100,9 +81,6 @@ async function interopDefault(module) {
100
81
  throw new Error(`Cannot import module: ${String(error)}`);
101
82
  }
102
83
  }
103
- function isPackageInScope(name) {
104
- return isPackageExists(name, { paths: [scopeUrl] });
105
- }
106
84
  function renameRules(rules, map) {
107
85
  return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
108
86
  for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
@@ -145,7 +123,15 @@ async function javascript() {
145
123
  linterOptions: { reportUnusedDisableDirectives: true },
146
124
  name: "cuiqg/javascript",
147
125
  plugins: { js: pluginJs },
148
- rules: { ...pluginJs.configs.recommended.rules }
126
+ rules: {
127
+ ...pluginJs.configs.recommended.rules,
128
+ "no-unused-vars": ["error", {
129
+ argsIgnorePattern: "^_",
130
+ caughtErrorsIgnorePattern: "^_",
131
+ ignoreRestSiblings: true,
132
+ varsIgnorePattern: "^_"
133
+ }]
134
+ }
149
135
  }];
150
136
  }
151
137
 
@@ -217,25 +203,21 @@ async function prettier() {
217
203
  //#endregion
218
204
  //#region src/configs/stylistic.js
219
205
  const stylisticConfigDefaults = {
206
+ experimental: false,
220
207
  indent: 2,
221
208
  jsx: true,
222
209
  quotes: "single",
223
- semi: false,
224
- commaDangle: "never"
210
+ semi: false
225
211
  };
226
212
  async function stylistic() {
227
213
  const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
228
214
  const config = pluginStylistic.configs.customize({
229
- commaDangle: "never",
230
- indent: 2,
231
- pluginName: "style",
232
- quotes: "single",
233
- semi: false,
234
- ...stylisticConfigDefaults
215
+ ...stylisticConfigDefaults,
216
+ commaDangle: "never"
235
217
  });
236
218
  return [{
237
219
  name: "cuiqg/stylistic",
238
- plugins: { style: pluginStylistic },
220
+ plugins: { "@stylistic": pluginStylistic },
239
221
  rules: { ...config.rules }
240
222
  }];
241
223
  }
@@ -263,6 +245,7 @@ async function vue() {
263
245
  computed: "readonly",
264
246
  defineEmits: "readonly",
265
247
  defineExpose: "readonly",
248
+ definePage: "readonly",
266
249
  defineModel: "readonly",
267
250
  defineOptions: "readonly",
268
251
  defineProps: "readonly",
@@ -404,118 +387,28 @@ async function tailwindcss() {
404
387
  name: "cuiqg/tailwindcss",
405
388
  plugins: { tailwindcss: pluginTailwindcss },
406
389
  languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
407
- rules: { ...pluginTailwindcss.configs["flat/recommended"][1].rules }
390
+ rules: { ...pluginTailwindcss.configs.recommended.rules },
391
+ settings: {}
408
392
  }];
409
393
  }
410
394
 
411
395
  //#endregion
412
- //#region src/configs/formatters.js
413
- function mergePrettierOptions(options, overrides = {}) {
414
- return {
415
- ...options,
416
- ...overrides,
417
- plugins: [...overrides.plugins || [], ...options.plugins || []]
418
- };
419
- }
420
- async function formatters(options = {}) {
421
- const isPrettierPluginXmlScope = isPackageInScope("@prettier/plugin-xml");
422
- const isPrettierPluginPhpScope = isPackageInScope("@prettier/plugin-php");
423
- const { config = {}, css = true, html = true, graphql = true, svg = isPrettierPluginXmlScope, xml = isPrettierPluginXmlScope, php = isPrettierPluginPhpScope } = options;
424
- const pluginFormat = await interopDefault(import("eslint-plugin-format"));
425
- const { indent, quotes, semi } = { ...stylisticConfigDefaults };
426
- const prettierOptions = Object.assign({
427
- endOfLine: "auto",
428
- printWidth: 120,
429
- semi,
430
- singleQuote: quotes === "single",
431
- tabWidth: typeof indent === "number" ? indent : 2,
432
- trailingComma: "all",
433
- useTabs: indent === "tab"
434
- }, config || {});
435
- const prettierXmlOptions = {
436
- bracketSameLine: true,
437
- singleAttributePerLine: false,
438
- tabWidth: 80,
439
- xmlQuoteAttributes: "double",
440
- xmlSelfClosingSpace: true,
441
- xmlSortAttributesByKey: false,
442
- xmlWhitespaceSensitivity: "ignore"
443
- };
444
- const prettierPhpOptions = {
445
- phpVersion: "auto",
446
- printWidth: 80,
447
- tabWidth: 4,
448
- useTabs: false,
449
- singleQuote: false,
450
- trailingCommaPHP: true,
451
- braceStyle: "per-cs",
452
- requirePragma: false,
453
- insertPragma: false
454
- };
455
- const configs = [{
456
- name: "cuiqg/formatter/setup",
457
- plugins: { format: pluginFormat }
396
+ //#region src/configs/imports.js
397
+ async function imports() {
398
+ const pluginImportX = await interopDefault(import("eslint-plugin-import-x"));
399
+ return [{
400
+ name: "cuiqg/imports",
401
+ plugins: { "import-x": pluginImportX },
402
+ 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"] }
458
411
  }];
459
- if (css) configs.push({
460
- name: "cuiqg/formatter/css",
461
- files: [GLOB_CSS, GLOB_POSTCSS],
462
- plugins: { format: parserPlain },
463
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "css" })] }
464
- }, {
465
- files: [GLOB_SCSS],
466
- languageOptions: { parser: parserPlain },
467
- name: "cuiqg/formatter/scss",
468
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "scss" })] }
469
- });
470
- if (html) configs.push({
471
- files: [GLOB_HTML],
472
- languageOptions: { parser: parserPlain },
473
- name: "cuiqg/formatter/html",
474
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
475
- });
476
- if (xml) configs.push({
477
- files: [GLOB_XML],
478
- languageOptions: { parser: parserPlain },
479
- name: "cuiqg/formatter/xml",
480
- rules: { "format/prettier": ["error", mergePrettierOptions({
481
- ...prettierXmlOptions,
482
- ...prettierOptions
483
- }, {
484
- parser: "xml",
485
- plugins: ["@prettier/plugin-xml"]
486
- })] }
487
- });
488
- if (svg) configs.push({
489
- files: [GLOB_SVG],
490
- languageOptions: { parser: parserPlain },
491
- name: "cuiqg/formatter/svg",
492
- rules: { "format/prettier": ["error", mergePrettierOptions({
493
- ...prettierXmlOptions,
494
- ...prettierOptions
495
- }, {
496
- parser: "xml",
497
- plugins: ["@prettier/plugin-xml"]
498
- })] }
499
- });
500
- if (graphql) configs.push({
501
- files: [GLOB_GRAPHQL],
502
- languageOptions: { parser: parserPlain },
503
- name: "cuiqg/formatter/graphql",
504
- rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "graphql" })] }
505
- });
506
- if (php) configs.push({
507
- files: [GLOB_PHP],
508
- languageOptions: { parser: parserPlain },
509
- name: "cuiqg/formatter/php",
510
- rules: { "format/prettier": ["error", mergePrettierOptions({
511
- ...prettierPhpOptions,
512
- ...prettierOptions
513
- }, {
514
- parser: "php",
515
- plugins: ["@prettier/plugin-php"]
516
- })] }
517
- });
518
- return configs;
519
412
  }
520
413
 
521
414
  //#endregion
@@ -537,33 +430,34 @@ const hasVue = () => [
537
430
  const hasTypeScript = () => isPackageExists("typescript");
538
431
  const hasUnocss = () => isPackageExists("unocss");
539
432
  const hasTailwindcss = () => isPackageExists("tailwindcss");
433
+ const hasPrettier = () => isPackageExists("prettier");
540
434
 
541
435
  //#endregion
542
436
  //#region src/presets.js
543
- const defaultPluginRenaming = {
544
- "@stylistic": "style",
545
- "@typescript-eslint": "ts"
546
- };
437
+ const defaultPluginRenaming = {};
547
438
  /**
548
439
  *
549
440
  * @param {object} options - 设置选项
550
- * @param {boolean} [options.prettier=false] - 是否启用 prettier 格式化
551
- * @param {boolean} [options.unocss] - 是否启用 unocss 格式化
552
- * @param {boolean} [options.tailwindcss] - 是否启用 tailwindcss 格式化
553
- * @param {boolean} [options.vue] - 是否启用 vue 格式化
554
- * @param {boolean|object} [options.formatter=true] - 是否启用格式化
441
+ * @param {boolean} [options.prettier] - 是否启用 Prettier 格式化
442
+ * @param {boolean} [options.unocss] - 是否启用 Unocss 格式化
443
+ * @param {boolean} [options.tailwindcss] - 是否启用 Tailwindcss 格式化
444
+ * @param {boolean} [options.vue] - 是否启用 VUE 格式化
445
+ * @param {boolean} [options.imports=true] - 是否启用 Import-X
446
+ * @param {boolean} [options.jsdoc=true] - 是否启用 JSDoc 格式化
555
447
  * @param {...Object} userConfigs - 用户配置
448
+ *
556
449
  * @returns {Promise<Object[]>} 合并后的配置
557
450
  */
558
451
  function cuiqg(options = {}, ...userConfigs) {
559
- const { prettier: enablePrettier = false, unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue(), formatter: enableFormatter = true } = options;
452
+ const { jsdoc: enableJsdoc = true, prettier: enablePrettier = hasPrettier(), unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue(), imports: enableImports = true } = options;
560
453
  const configs = [];
561
- configs.push(ignores(), javascript(), jsdoc(), stylistic(), packageJson());
454
+ configs.push(ignores(), javascript(), stylistic(), packageJson());
455
+ if (enableJsdoc) configs.push(jsdoc());
456
+ if (enableImports) configs.push(imports());
562
457
  if (enableVue) configs.push(vue(), macros());
563
458
  if (enableUnocss) configs.push(unocss());
564
459
  if (enableTailwindcss) configs.push(tailwindcss());
565
460
  if (enablePrettier) configs.push(prettier());
566
- if (enableFormatter) configs.push(formatters(typeof enableFormatter === "object" ? enableFormatter : {}));
567
461
  let composer = new FlatConfigComposer();
568
462
  composer = composer.append(...configs, ...userConfigs).renamePlugins(defaultPluginRenaming);
569
463
  return composer;
@@ -574,4 +468,4 @@ function cuiqg(options = {}, ...userConfigs) {
574
468
  var src_default = cuiqg;
575
469
 
576
470
  //#endregion
577
- 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, formatters, hasTailwindcss, hasTypeScript, hasUnocss, hasVue, ignores, isInEditor, isInGitHookOrLintStaged, javascript, jsdoc, macros, packageJson, prettier, stylistic, stylisticConfigDefaults, tailwindcss, unocss, vue };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuiqg/eslint-config",
3
- "version": "2.8.2",
3
+ "version": "2.8.4",
4
4
  "description": "Eslint config for @cuiqg",
5
5
  "keywords": [
6
6
  "eslint-config"
@@ -23,8 +23,16 @@
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
+ "scripts": {
27
+ "build": "tsdown",
28
+ "dev": "tsdown --watch",
29
+ "build:inspect": "npx @eslint/config-inspector build --config eslint-inspector.config.js",
30
+ "lint": "eslint .",
31
+ "lint:inspect": "npx @eslint/config-inspector --open false --config eslint-inspector.config.js",
32
+ "prepublishOnly": "npm run build",
33
+ "release": "bumpp"
34
+ },
26
35
  "devDependencies": {
27
- "@cuiqg/prettier-config": "latest",
28
36
  "@eslint/config-inspector": "^1.4.2",
29
37
  "@eslint/eslintrc": "^3.3.3",
30
38
  "bumpp": "^10.3.2",
@@ -43,6 +51,7 @@
43
51
  "eslint-config-prettier": "^10.1.8",
44
52
  "eslint-flat-config-utils": "^2.1.4",
45
53
  "eslint-plugin-format": "^1.0.2",
54
+ "eslint-plugin-import-x": "^4.16.1",
46
55
  "eslint-plugin-jsdoc": "^61.4.1",
47
56
  "eslint-plugin-package-json": "^0.85.0",
48
57
  "eslint-plugin-prettier": "^5.5.4",
@@ -52,14 +61,5 @@
52
61
  "jsonc-eslint-parser": "^2.4.1",
53
62
  "local-pkg": "^1.1.2",
54
63
  "vue-eslint-parser": "^10.2.0"
55
- },
56
- "prettier": "@cuiqg/prettier-config",
57
- "scripts": {
58
- "build": "tsdown",
59
- "dev": "tsdown --watch",
60
- "build:inspect": "pnpx @eslint/config-inspector build --config eslint-inspector.config.js",
61
- "lint": "eslint .",
62
- "lint:inspect": "pnpx @eslint/config-inspector --open false --config eslint-inspector.config.js",
63
- "release": "bumpp"
64
64
  }
65
- }
65
+ }