@cuiqg/eslint-config 2.8.9 → 2.8.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.
Files changed (2) hide show
  1. package/dist/index.mjs +187 -182
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -84,43 +84,24 @@ async function ignores() {
84
84
  })];
85
85
  }
86
86
 
87
- //#endregion
88
- //#region src/env.js
89
- const isInGitHookOrLintStaged = () => {
90
- return !!(process$1.env.GIT_PARAMS || process$1.env.VSCODE_GIT_COMMAND || process$1.env.npm_lifecycle_script?.startsWith("lint-staged"));
91
- };
92
- const isInEditor = () => {
93
- if (process$1.env.CI) return false;
94
- if (isInGitHookOrLintStaged()) return false;
95
- return !!(process$1.env.VSCODE_PID || process$1.env.VSCODE_CWD || process$1.env.JETBRAINS_IDE || process$1.env.VIM || process$1.env.NVIM);
96
- };
97
- const hasVue = () => isPackageExists("vue");
98
- const hasTypeScript = () => isPackageExists("typescript");
99
- const hasUnocss = () => isPackageExists("unocss");
100
- const hasTailwindcss = () => isPackageExists("tailwindcss");
101
-
102
87
  //#endregion
103
88
  //#region src/configs/javascript.js
104
- async function javascript() {
105
- const files = [GLOB_SRC];
89
+ async function javascript(options = {}) {
90
+ const { isInEditor: isInEditor$1 = false } = options;
106
91
  const pluginUnusedImports = await interopDefault(import("eslint-plugin-unused-imports"));
107
92
  return [{
108
- files,
109
93
  name: "cuiqg/javascript",
110
94
  plugins: { "unused-imports": pluginUnusedImports },
111
95
  languageOptions: {
112
- ecmaVersion: "latest",
113
96
  globals: {
114
97
  ...globals.browser,
115
98
  ...globals.es2025,
116
99
  ...globals.node
117
100
  },
118
101
  parserOptions: {
119
- ecmaFeatures: { jsx: true },
120
102
  ecmaVersion: "latest",
121
103
  sourceType: "module"
122
- },
123
- sourceType: "module"
104
+ }
124
105
  },
125
106
  linterOptions: { reportUnusedDisableDirectives: true },
126
107
  rules: {
@@ -285,7 +266,7 @@ async function javascript() {
285
266
  allowNamedFunctions: false,
286
267
  allowUnboundThis: true
287
268
  }],
288
- "prefer-const": [isInEditor ? "warn" : "error", {
269
+ "prefer-const": [isInEditor$1 ? "warn" : "error", {
289
270
  destructuring: "all",
290
271
  ignoreReadBeforeAssign: true
291
272
  }],
@@ -297,7 +278,7 @@ async function javascript() {
297
278
  "prefer-template": "error",
298
279
  "symbol-description": "error",
299
280
  "unicode-bom": ["error", "never"],
300
- "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
281
+ "unused-imports/no-unused-imports": isInEditor$1 ? "warn" : "error",
301
282
  "unused-imports/no-unused-vars": ["error", {
302
283
  args: "after-used",
303
284
  argsIgnorePattern: "^_",
@@ -340,7 +321,8 @@ async function jsdoc() {
340
321
  "jsdoc/require-yields-check": "warn",
341
322
  "jsdoc/check-alignment": "warn",
342
323
  "jsdoc/multiline-blocks": "warn"
343
- }
324
+ },
325
+ settings: { jsdoc: { mode: "jsdoc" } }
344
326
  }];
345
327
  }
346
328
 
@@ -414,17 +396,35 @@ const stylisticConfigDefaults = {
414
396
  quotes: "single",
415
397
  semi: false
416
398
  };
417
- async function stylistic() {
399
+ async function stylistic(options = {}) {
400
+ const { commaDangle = "never", experimental, indent, jsx, quotes, semi } = {
401
+ ...stylisticConfigDefaults,
402
+ ...options
403
+ };
418
404
  const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
419
405
  const config = pluginStylistic.configs.customize({
420
- ...stylisticConfigDefaults,
421
- commaDangle: "never",
422
- pluginName: "@stylistic"
406
+ commaDangle,
407
+ experimental,
408
+ indent,
409
+ jsx,
410
+ pluginName: "@stylistic",
411
+ quotes,
412
+ semi
423
413
  });
424
414
  return [{
425
415
  name: "cuiqg/stylistic",
426
416
  plugins: { "@stylistic": pluginStylistic },
427
- rules: { ...config.rules }
417
+ rules: {
418
+ ...config.rules,
419
+ "@stylistic/generator-star-spacing": ["error", {
420
+ after: true,
421
+ before: false
422
+ }],
423
+ "@stylistic/yield-star-spacing": ["error", {
424
+ after: true,
425
+ before: false
426
+ }]
427
+ }
428
428
  }];
429
429
  }
430
430
 
@@ -444,178 +444,164 @@ async function unocss() {
444
444
 
445
445
  //#endregion
446
446
  //#region src/configs/vue.js
447
- async function vue() {
448
- let additionalParserOptions = {};
447
+ async function vue(options = {}) {
448
+ const { typescript: typescript$1 = false, stylistic: stylistic$1 = true, vueVersion = 3 } = options;
449
+ let parserOptions = null;
449
450
  const files = [GLOB_VUE];
451
+ const { indent = 2 } = typeof stylistic$1 === "boolean" ? {} : stylistic$1;
450
452
  const [pluginVue, parserVue] = await Promise.all([interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser"))]);
451
- if (hasTypeScript) {
452
- const parserTs = await interopDefault(import("@typescript-eslint/parser"));
453
- additionalParserOptions = {
454
- ...additionalParserOptions,
455
- parser: parserTs,
456
- projectService: true,
457
- tsconfigRootDir: process.cwd()
458
- };
459
- }
453
+ if (typescript$1) parserOptions = { parser: await interopDefault(import("@typescript-eslint/parser")) };
460
454
  return [{
461
455
  files,
462
456
  name: "cuiqg/vue",
463
457
  plugins: { vue: pluginVue },
464
458
  languageOptions: {
459
+ globals: {
460
+ computed: "readonly",
461
+ defineEmits: "readonly",
462
+ defineExpose: "readonly",
463
+ defineProps: "readonly",
464
+ onMounted: "readonly",
465
+ onUnmounted: "readonly",
466
+ reactive: "readonly",
467
+ ref: "readonly",
468
+ shallowReactive: "readonly",
469
+ shallowRef: "readonly",
470
+ toRef: "readonly",
471
+ toRefs: "readonly",
472
+ watch: "readonly",
473
+ watchEffect: "readonly"
474
+ },
465
475
  parser: parserVue,
466
476
  parserOptions: {
477
+ ecmaFeatures: { jsx: true },
467
478
  ecmaVersion: "latest",
468
479
  extraFileExtensions: [".vue"],
469
480
  sourceType: "module",
470
- ...additionalParserOptions
481
+ ...parserOptions
471
482
  }
472
483
  },
473
484
  processor: pluginVue.processors[".vue"],
474
485
  rules: {
475
- "vue/attribute-hyphenation": ["error", "always"],
486
+ ...pluginVue.configs.base.rules,
487
+ ...vueVersion === 2 ? {
488
+ ...pluginVue.configs["vue2-essential"].rules,
489
+ ...pluginVue.configs["vue2-strongly-recommended"].rules,
490
+ ...pluginVue.configs["vue2-recommended"].rules
491
+ } : {
492
+ ...pluginVue.configs["flat/essential"].map((c) => c.rules).reduce((acc, c) => ({
493
+ ...acc,
494
+ ...c
495
+ }), {}),
496
+ ...pluginVue.configs["flat/strongly-recommended"].map((c) => c.rules).reduce((acc, c) => ({
497
+ ...acc,
498
+ ...c
499
+ }), {}),
500
+ ...pluginVue.configs["flat/recommended"].map((c) => c.rules).reduce((acc, c) => ({
501
+ ...acc,
502
+ ...c
503
+ }), {})
504
+ },
476
505
  "vue/block-order": ["error", { order: [
477
506
  "script",
478
507
  "template",
479
508
  "style"
480
509
  ] }],
481
- "vue/comment-directive": "error",
482
- "vue/component-api-style": "error",
483
- "vue/component-definition-name-casing": ["error", "kebab-case"],
484
- "vue/component-name-in-template-casing": ["error", "kebab-case"],
485
- "vue/component-options-name-casing": ["error", "kebab-case"],
486
- "vue/custom-event-name-casing": ["error", "kebab-case"],
487
- "vue/define-emits-declaration": "error",
488
- "vue/define-props-declaration": "error",
489
- "vue/define-props-destructuring": ["error", { destructure: "always" }],
490
- "vue/enforce-style-attribute": ["error", { allow: ["scoped", "plain"] }],
491
- "vue/html-button-has-type": "error",
492
- "vue/html-end-tags": "error",
493
- "vue/jsx-uses-vars": "error",
494
- "vue/no-async-in-computed-properties": "error",
495
- "vue/no-child-content": "error",
496
- "vue/no-computed-properties-in-data": "error",
497
- "vue/no-deprecated-data-object-declaration": "error",
498
- "vue/no-deprecated-delete-set": "error",
499
- "vue/no-deprecated-destroyed-lifecycle": "error",
500
- "vue/no-deprecated-dollar-listeners-api": "error",
501
- "vue/no-deprecated-dollar-scopedslots-api": "error",
502
- "vue/no-deprecated-events-api": "error",
503
- "vue/no-deprecated-filter": "error",
504
- "vue/no-deprecated-functional-template": "error",
505
- "vue/no-deprecated-html-element-is": "error",
506
- "vue/no-deprecated-inline-template": "error",
507
- "vue/no-deprecated-model-definition": "error",
508
- "vue/no-deprecated-props-default-this": "error",
509
- "vue/no-deprecated-router-link-tag-prop": "error",
510
- "vue/no-deprecated-scope-attribute": "error",
511
- "vue/no-deprecated-slot-attribute": "error",
512
- "vue/no-deprecated-slot-scope-attribute": "error",
513
- "vue/no-deprecated-v-bind-sync": "error",
514
- "vue/no-deprecated-v-is": "error",
515
- "vue/no-deprecated-v-on-native-modifier": "error",
516
- "vue/no-deprecated-v-on-number-modifiers": "error",
517
- "vue/no-deprecated-vue-config-keycodes": "error",
518
- "vue/no-dupe-keys": "error",
519
- "vue/no-dupe-v-else-if": "error",
520
- "vue/no-duplicate-attr-inheritance": "error",
521
- "vue/no-duplicate-attributes": "error",
522
- "vue/no-duplicate-class-names": "error",
523
- "vue/no-empty-component-block": "error",
524
- "vue/no-export-in-script-setup": "error",
525
- "vue/no-expose-after-await": "error",
526
- "vue/no-lifecycle-after-await": "error",
527
- "vue/no-lone-template": "error",
528
- "vue/no-multiple-objects-in-class": "error",
529
- "vue/no-multiple-slot-args": "error",
530
- "vue/no-mutating-props": "error",
531
- "vue/no-negated-condition": "error",
532
- "vue/no-negated-v-if-condition": "error",
533
- "vue/no-parsing-error": "error",
534
- "vue/no-potential-component-option-typo": "error",
535
- "vue/no-ref-as-operand": "error",
536
- "vue/no-ref-object-reactivity-loss": "error",
537
- "vue/no-required-prop-with-default": "error",
538
- "vue/no-reserved-component-names": "error",
539
- "vue/no-reserved-keys": "error",
540
- "vue/no-reserved-props": "error",
541
- "vue/no-setup-props-reactivity-loss": "error",
542
- "vue/no-shared-component-data": "error",
543
- "vue/no-side-effects-in-computed-properties": "error",
544
- "vue/no-template-key": "error",
545
- "vue/no-template-shadow": "error",
546
- "vue/no-template-target-blank": "error",
547
- "vue/no-textarea-mustache": "error",
548
- "vue/no-this-in-before-route-enter": "error",
549
- "vue/no-undef-components": "error",
550
- "vue/no-undef-properties": "error",
551
- "vue/no-unused-components": "error",
552
- "vue/no-unused-emit-declarations": "error",
553
- "vue/no-unused-vars": "error",
554
- "vue/no-use-computed-property-like-method": "error",
555
- "vue/no-use-v-else-with-v-for": "error",
556
- "vue/no-use-v-if-with-v-for": "error",
557
- "vue/no-useless-mustaches": "error",
558
- "vue/no-useless-template-attributes": "error",
510
+ "vue/component-name-in-template-casing": ["error", "PascalCase"],
511
+ "vue/component-options-name-casing": ["error", "PascalCase"],
512
+ "vue/component-tags-order": "off",
513
+ "vue/custom-event-name-casing": ["error", "camelCase"],
514
+ "vue/define-macros-order": ["error", { order: [
515
+ "defineOptions",
516
+ "defineProps",
517
+ "defineEmits",
518
+ "defineSlots"
519
+ ] }],
520
+ "vue/dot-location": ["error", "property"],
521
+ "vue/dot-notation": ["error", { allowKeywords: true }],
522
+ "vue/eqeqeq": ["error", "smart"],
523
+ "vue/html-indent": ["error", indent],
524
+ "vue/html-quotes": ["error", "double"],
525
+ "vue/max-attributes-per-line": "off",
526
+ "vue/multi-word-component-names": "off",
527
+ "vue/no-dupe-keys": "off",
528
+ "vue/no-empty-pattern": "error",
529
+ "vue/no-irregular-whitespace": "error",
530
+ "vue/no-loss-of-precision": "error",
531
+ "vue/no-restricted-syntax": [
532
+ "error",
533
+ "DebuggerStatement",
534
+ "LabeledStatement",
535
+ "WithStatement"
536
+ ],
537
+ "vue/no-restricted-v-bind": ["error", "/^v-/"],
538
+ "vue/no-setup-props-reactivity-loss": "off",
539
+ "vue/no-sparse-arrays": "error",
540
+ "vue/no-unused-refs": "error",
559
541
  "vue/no-useless-v-bind": "error",
560
- "vue/no-v-for-template-key-on-child": "error",
561
- "vue/no-v-html": "error",
562
- "vue/no-v-text-v-html-on-component": "error",
563
- "vue/no-watch-after-await": "error",
564
- "vue/prefer-define-options": "error",
565
- "vue/prefer-import-from-vue": "error",
542
+ "vue/no-v-html": "off",
543
+ "vue/object-shorthand": [
544
+ "error",
545
+ "always",
546
+ {
547
+ avoidQuotes: true,
548
+ ignoreConstructors: false
549
+ }
550
+ ],
566
551
  "vue/prefer-separate-static-class": "error",
567
- "vue/prefer-true-attribute-shorthand": "error",
552
+ "vue/prefer-template": "error",
568
553
  "vue/prop-name-casing": ["error", "camelCase"],
569
- "vue/require-component-is": "error",
570
- "vue/require-default-prop": "error",
571
- "vue/require-emit-validator": "error",
572
- "vue/require-explicit-emits": "error",
573
- "vue/require-explicit-slots": "error",
574
- "vue/require-macro-variable-name": ["error", {
575
- defineEmits: "emit",
576
- defineProps: "props",
577
- defineSlots: "slots",
578
- useAttrs: "attrs",
579
- useSlots: "slots"
554
+ "vue/require-default-prop": "off",
555
+ "vue/require-prop-types": "off",
556
+ "vue/space-infix-ops": "error",
557
+ "vue/space-unary-ops": ["error", {
558
+ nonwords: false,
559
+ words: true
580
560
  }],
581
- "vue/require-name-property": "error",
582
- "vue/require-prop-type-constructor": "error",
583
- "vue/require-render-return": "error",
584
- "vue/require-slots-as-functions": "error",
585
- "vue/require-toggle-inside-transition": "error",
586
- "vue/require-typed-ref": "error",
587
- "vue/require-v-for-key": "error",
588
- "vue/require-valid-default-prop": "error",
589
- "vue/return-in-computed-property": "error",
590
- "vue/return-in-emits-validator": "error",
591
- "vue/this-in-template": "error",
592
- "vue/use-v-on-exact": "error",
593
- "vue/v-bind-style": "error",
594
- "vue/v-on-event-hyphenation": "error",
595
- "vue/v-on-style": "error",
596
- "vue/v-slot-style": "error",
597
- "vue/valid-attribute-name": "error",
598
- "vue/valid-define-emits": "error",
599
- "vue/valid-define-options": "error",
600
- "vue/valid-define-props": "error",
601
- "vue/valid-next-tick": "error",
602
- "vue/valid-template-root": "error",
603
- "vue/valid-v-bind": "error",
604
- "vue/valid-v-cloak": "error",
605
- "vue/valid-v-else": "error",
606
- "vue/valid-v-else-if": "error",
607
- "vue/valid-v-for": "error",
608
- "vue/valid-v-html": "error",
609
- "vue/valid-v-if": "error",
610
- "vue/valid-v-is": "error",
611
- "vue/valid-v-memo": "error",
612
- "vue/valid-v-model": "error",
613
- "vue/valid-v-on": "error",
614
- "vue/valid-v-once": "error",
615
- "vue/valid-v-pre": "error",
616
- "vue/valid-v-show": "error",
617
- "vue/valid-v-slot": "error",
618
- "vue/valid-v-text": "error"
561
+ ...stylistic$1 ? {
562
+ "vue/array-bracket-spacing": ["error", "never"],
563
+ "vue/arrow-spacing": ["error", {
564
+ after: true,
565
+ before: true
566
+ }],
567
+ "vue/block-spacing": ["error", "always"],
568
+ "vue/block-tag-newline": ["error", {
569
+ multiline: "always",
570
+ singleline: "always"
571
+ }],
572
+ "vue/brace-style": [
573
+ "error",
574
+ "stroustrup",
575
+ { allowSingleLine: true }
576
+ ],
577
+ "vue/comma-dangle": ["error", "always-multiline"],
578
+ "vue/comma-spacing": ["error", {
579
+ after: true,
580
+ before: false
581
+ }],
582
+ "vue/comma-style": ["error", "last"],
583
+ "vue/html-comment-content-spacing": [
584
+ "error",
585
+ "always",
586
+ { exceptions: ["-"] }
587
+ ],
588
+ "vue/key-spacing": ["error", {
589
+ afterColon: true,
590
+ beforeColon: false
591
+ }],
592
+ "vue/keyword-spacing": ["error", {
593
+ after: true,
594
+ before: true
595
+ }],
596
+ "vue/object-curly-newline": "off",
597
+ "vue/object-curly-spacing": ["error", "always"],
598
+ "vue/object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
599
+ "vue/operator-linebreak": ["error", "before"],
600
+ "vue/padding-line-between-blocks": ["error", "always"],
601
+ "vue/quote-props": ["error", "consistent-as-needed"],
602
+ "vue/space-in-parens": ["error", "never"],
603
+ "vue/template-curly-spacing": "error"
604
+ } : {}
619
605
  }
620
606
  }];
621
607
  }
@@ -652,7 +638,11 @@ async function comments() {
652
638
  //#endregion
653
639
  //#region src/configs/typescript.js
654
640
  async function typescript() {
655
- const files = [GLOB_TS, GLOB_TSX];
641
+ const files = [
642
+ GLOB_TS,
643
+ GLOB_TSX,
644
+ GLOB_VUE
645
+ ];
656
646
  const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
657
647
  return [{
658
648
  files,
@@ -836,14 +826,29 @@ async function typescript() {
836
826
  }];
837
827
  }
838
828
 
829
+ //#endregion
830
+ //#region src/env.js
831
+ const isInGitHookOrLintStaged = () => {
832
+ return !!(process$1.env.GIT_PARAMS || process$1.env.VSCODE_GIT_COMMAND || process$1.env.npm_lifecycle_script?.startsWith("lint-staged"));
833
+ };
834
+ const isInEditor = () => {
835
+ if (process$1.env.CI) return false;
836
+ if (isInGitHookOrLintStaged()) return false;
837
+ return !!(process$1.env.VSCODE_PID || process$1.env.VSCODE_CWD || process$1.env.JETBRAINS_IDE || process$1.env.VIM || process$1.env.NVIM);
838
+ };
839
+ const hasVue = () => isPackageExists("vue");
840
+ const hasTypeScript = () => isPackageExists("typescript");
841
+ const hasUnocss = () => isPackageExists("unocss");
842
+ const hasTailwindcss = () => isPackageExists("tailwindcss");
843
+
839
844
  //#endregion
840
845
  //#region src/presets.js
841
846
  /**
842
847
  *
843
848
  * @param {object} options - 设置选项
844
- * @param {boolean} [options.prettier=false] - 是否启用 Prettier 格式化
849
+ * @param {boolean} [options.typescript] - 是否启用 TypeScript 格式化
845
850
  * @param {boolean} [options.unocss] - 是否启用 Unocss 格式化
846
- * @param {boolean} [options.tailwindcss] - 是否启用 Tailwindcss 格式化
851
+ * @param {boolean} [options.tailwindcss] - 是否启用 TailwindCSS 格式化
847
852
  * @param {boolean} [options.vue] - 是否启用 VUE 格式化
848
853
  * @param {boolean} [options.jsdoc=true] - 是否启用 JSDoc 格式化
849
854
  * @param {...Object} userConfigs - 用户配置
@@ -853,10 +858,10 @@ async function typescript() {
853
858
  function cuiqg(options = {}, ...userConfigs) {
854
859
  const { jsdoc: enableJsdoc = true, unocss: enableUnocss = hasUnocss(), tailwindcss: enableTailwindcss = hasTailwindcss(), typescript: enableTypescript = hasTypeScript(), vue: enableVue = hasVue() } = options;
855
860
  const configs = [];
856
- configs.push(ignores(), comments(), javascript(), stylistic(), packageJson());
861
+ configs.push(ignores(), comments(), javascript({ isInEditor }), stylistic(), packageJson());
857
862
  if (enableTypescript) configs.push(typescript());
858
863
  if (enableJsdoc) configs.push(jsdoc());
859
- if (enableVue) configs.push(vue(), macros());
864
+ if (enableVue) configs.push(vue({ typescript: enableTypescript }), macros());
860
865
  if (enableUnocss) configs.push(unocss());
861
866
  if (enableTailwindcss) configs.push(tailwindcss());
862
867
  let composer = new FlatConfigComposer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuiqg/eslint-config",
3
- "version": "2.8.9",
3
+ "version": "2.8.10",
4
4
  "description": "Eslint config for @cuiqg",
5
5
  "keywords": [
6
6
  "eslint-config"