@cuiqg/eslint-config 2.8.2 → 2.8.3

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 +28 -148
  2. package/package.json +2 -1
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,18 @@ 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
- const config = pluginStylistic.configs.customize({
229
- commaDangle: "never",
230
- indent: 2,
231
- pluginName: "style",
232
- quotes: "single",
233
- semi: false,
234
- ...stylisticConfigDefaults
235
- });
214
+ const config = pluginStylistic.configs.customize({ ...stylisticConfigDefaults });
236
215
  return [{
237
216
  name: "cuiqg/stylistic",
238
- plugins: { style: pluginStylistic },
217
+ plugins: { "@stylistic": pluginStylistic },
239
218
  rules: { ...config.rules }
240
219
  }];
241
220
  }
@@ -263,6 +242,7 @@ async function vue() {
263
242
  computed: "readonly",
264
243
  defineEmits: "readonly",
265
244
  defineExpose: "readonly",
245
+ definePage: "readonly",
266
246
  defineModel: "readonly",
267
247
  defineOptions: "readonly",
268
248
  defineProps: "readonly",
@@ -404,118 +384,21 @@ async function tailwindcss() {
404
384
  name: "cuiqg/tailwindcss",
405
385
  plugins: { tailwindcss: pluginTailwindcss },
406
386
  languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
407
- rules: { ...pluginTailwindcss.configs["flat/recommended"][1].rules }
387
+ rules: { ...pluginTailwindcss.configs.recommended.rules },
388
+ settings: {}
408
389
  }];
409
390
  }
410
391
 
411
392
  //#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 }
393
+ //#region src/configs/imports.js
394
+ async function imports() {
395
+ const pluginImportX = await interopDefault(import("eslint-plugin-import-x"));
396
+ return [{
397
+ name: "cuiqg/imports",
398
+ plugins: { "import-x": pluginImportX },
399
+ rules: { ...pluginImportX.configs["flat/recommended"].rules },
400
+ settings: { "import-x/core-modules": ["electron", "vue-router/auto-routes"] }
458
401
  }];
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
402
  }
520
403
 
521
404
  //#endregion
@@ -540,10 +423,7 @@ const hasTailwindcss = () => isPackageExists("tailwindcss");
540
423
 
541
424
  //#endregion
542
425
  //#region src/presets.js
543
- const defaultPluginRenaming = {
544
- "@stylistic": "style",
545
- "@typescript-eslint": "ts"
546
- };
426
+ const defaultPluginRenaming = {};
547
427
  /**
548
428
  *
549
429
  * @param {object} options - 设置选项
@@ -556,14 +436,14 @@ const defaultPluginRenaming = {
556
436
  * @returns {Promise<Object[]>} 合并后的配置
557
437
  */
558
438
  function cuiqg(options = {}, ...userConfigs) {
559
- const { prettier: enablePrettier = false, unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue(), formatter: enableFormatter = true } = options;
439
+ const { prettier: enablePrettier = false, unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), vue: enableVue = hasVue(), imports: enableImports = true } = options;
560
440
  const configs = [];
561
441
  configs.push(ignores(), javascript(), jsdoc(), stylistic(), packageJson());
442
+ if (enableImports) configs.push(imports());
562
443
  if (enableVue) configs.push(vue(), macros());
563
444
  if (enableUnocss) configs.push(unocss());
564
445
  if (enableTailwindcss) configs.push(tailwindcss());
565
446
  if (enablePrettier) configs.push(prettier());
566
- if (enableFormatter) configs.push(formatters(typeof enableFormatter === "object" ? enableFormatter : {}));
567
447
  let composer = new FlatConfigComposer();
568
448
  composer = composer.append(...configs, ...userConfigs).renamePlugins(defaultPluginRenaming);
569
449
  return composer;
@@ -574,4 +454,4 @@ function cuiqg(options = {}, ...userConfigs) {
574
454
  var src_default = cuiqg;
575
455
 
576
456
  //#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 };
457
+ 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, 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.3",
4
4
  "description": "Eslint config for @cuiqg",
5
5
  "keywords": [
6
6
  "eslint-config"
@@ -43,6 +43,7 @@
43
43
  "eslint-config-prettier": "^10.1.8",
44
44
  "eslint-flat-config-utils": "^2.1.4",
45
45
  "eslint-plugin-format": "^1.0.2",
46
+ "eslint-plugin-import-x": "^4.16.1",
46
47
  "eslint-plugin-jsdoc": "^61.4.1",
47
48
  "eslint-plugin-package-json": "^0.85.0",
48
49
  "eslint-plugin-prettier": "^5.5.4",