my-code-style 1.2.0 → 1.5.0

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.
@@ -16,8 +16,28 @@ module.exports = {
16
16
  parserOptions: {
17
17
  ecmaVersion: "latest",
18
18
  sourceType: "module",
19
+ ecmaFeatures: {
20
+ jsx: true,
21
+ },
19
22
  },
23
+ // Mirrors the ignores of src/eslint/flat/base.mjs: without them `eslint .`
24
+ // lints build output (dist/, coverage/) and fails on generated code.
25
+ ignorePatterns: [
26
+ "**/node_modules/**",
27
+ "**/dist/**",
28
+ "**/coverage/**",
29
+ "**/public/**",
30
+ "**/assets/iconfont/**",
31
+ "**/*.min.js",
32
+ "**/*.min.css",
33
+ ],
20
34
  plugins: ["@typescript-eslint", "prettier", "import"],
35
+ overrides: [
36
+ {
37
+ files: ["**/*.cjs", "**/.*rc.js", "**/*.config.js"],
38
+ rules: { "@typescript-eslint/no-require-imports": "off" },
39
+ },
40
+ ],
21
41
  rules: {
22
42
  // Prettier 集成
23
43
  "prettier/prettier": [
@@ -31,9 +51,12 @@ module.exports = {
31
51
  },
32
52
  ],
33
53
  // 格式化与风格
34
- indent: ["error", 4],
54
+ indent: "off",
35
55
  semi: ["error", "never"],
36
- quotes: ["error", "double", { avoidEscape: false, allowTemplateLiterals: true }],
56
+ // avoidEscape must stay true: Prettier keeps the cheaper quote when a
57
+ // string contains double quotes ('say "hi"'), so requiring an escape
58
+ // here produces an error that --fix can never resolve.
59
+ quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
37
60
  curly: ["error", "all"],
38
61
  "comma-dangle": ["error", "always-multiline"],
39
62
  "object-curly-spacing": ["error", "always"],
@@ -53,6 +76,9 @@ module.exports = {
53
76
  "@typescript-eslint/no-redeclare": "error",
54
77
  "@typescript-eslint/no-explicit-any": "off",
55
78
  "@typescript-eslint/no-unused-vars": "off",
79
+ "@typescript-eslint/no-unused-expressions": "off",
80
+ "@typescript-eslint/ban-ts-comment": "off",
81
+ "@typescript-eslint/no-empty-object-type": "off",
56
82
 
57
83
  // 常用关闭
58
84
  "no-console": "off",
@@ -62,6 +88,7 @@ module.exports = {
62
88
  "no-use-before-define": "off",
63
89
  "no-undef": "off",
64
90
  "no-unused-vars": "off",
91
+ "no-unused-expressions": "off",
65
92
  "no-param-reassign": "off",
66
93
  "no-redeclare": "off",
67
94
  "prefer-promise-reject-errors": "off",
@@ -75,4 +102,3 @@ module.exports = {
75
102
  "import/resolver": { typescript: {} },
76
103
  },
77
104
  }
78
-
@@ -20,10 +20,13 @@ export const prettierRules = {
20
20
  * Common rules shared across all flat config levels — mirrors base.cjs rules
21
21
  */
22
22
  export const commonRules = {
23
- // 缩进与换行
24
- indent: ["error", 4],
23
+ // 缩进由 Prettier 统一负责,关闭 ESLint 缩进避免打架
24
+ indent: "off",
25
25
  semi: ["error", "never"],
26
- quotes: ["error", "double", { avoidEscape: false, allowTemplateLiterals: true }],
26
+ // avoidEscape must stay true: Prettier keeps the cheaper quote when a
27
+ // string contains double quotes ('say "hi"'), so requiring an escape here
28
+ // produces an error that --fix can never resolve.
29
+ quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
27
30
  curly: ["error", "all"],
28
31
  "comma-dangle": ["error", "always-multiline"],
29
32
  "object-curly-spacing": ["error", "always"],
@@ -31,11 +34,7 @@ export const commonRules = {
31
34
 
32
35
  // Import rules (using import-x for flat config compatibility)
33
36
  "import-x/no-unresolved": "off",
34
- "import-x/extensions": [
35
- "error",
36
- "ignorePackages",
37
- { js: "never", jsx: "never", ts: "never", tsx: "never" },
38
- ],
37
+ "import-x/extensions": "off",
39
38
  "import-x/prefer-default-export": "off",
40
39
  "import-x/no-extraneous-dependencies": "off",
41
40
 
@@ -43,6 +42,9 @@ export const commonRules = {
43
42
  "@typescript-eslint/no-redeclare": "error",
44
43
  "@typescript-eslint/no-explicit-any": "off",
45
44
  "@typescript-eslint/no-unused-vars": "off",
45
+ "@typescript-eslint/no-unused-expressions": "off",
46
+ "@typescript-eslint/ban-ts-comment": "off",
47
+ "@typescript-eslint/no-empty-object-type": "off",
46
48
 
47
49
  // Commonly disabled
48
50
  "no-console": "off",
@@ -52,6 +54,7 @@ export const commonRules = {
52
54
  "no-use-before-define": "off",
53
55
  "no-undef": "off",
54
56
  "no-unused-vars": "off",
57
+ "no-unused-expressions": "off",
55
58
  "no-param-reassign": "off",
56
59
  "no-redeclare": "off",
57
60
  "prefer-promise-reject-errors": "off",
@@ -76,4 +79,3 @@ export const uniappGlobals = {
76
79
  App: true,
77
80
  NodeJS: true,
78
81
  }
79
-
@@ -11,7 +11,15 @@ import { prettierRules, commonRules } from "./_shared.mjs"
11
11
  export default [
12
12
  // Ignore patterns
13
13
  {
14
- ignores: ["**/node_modules/**", "**/dist/**", "**/coverage/**"],
14
+ ignores: [
15
+ "**/node_modules/**",
16
+ "**/dist/**",
17
+ "**/coverage/**",
18
+ "**/public/**",
19
+ "**/assets/iconfont/**",
20
+ "**/*.min.js",
21
+ "**/*.min.css",
22
+ ],
15
23
  },
16
24
 
17
25
  // TypeScript recommended rules
@@ -19,9 +27,9 @@ export default [
19
27
  ...tseslint.configs.recommended,
20
28
 
21
29
  // eslint-plugin-import-x configuration
22
- // Replaces: plugin:import/recommended + eslint-config-standard (via FlatCompat)
30
+ // Replaces: plugin:import/recommended (ESLint 8 equivalent in src/eslint/base.cjs)
23
31
  {
24
- files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
32
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx,vue,nvue}"],
25
33
  plugins: {
26
34
  "import-x": importX,
27
35
  },
@@ -36,16 +44,9 @@ export default [
36
44
  },
37
45
  },
38
46
 
39
- // Prettier integration
40
- // Replaces: extends: ["plugin:prettier/recommended"]
41
- eslintPluginPrettierRecommended,
42
-
43
- // eslint-config-prettier MUST be last — disables conflicting ESLint rules
44
- eslintConfigPrettier,
45
-
46
- // Global language options for JS/TS
47
+ // Global language options for JS/TS/JSX/TSX
47
48
  {
48
- files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
49
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
49
50
  languageOptions: {
50
51
  ecmaVersion: "latest",
51
52
  sourceType: "module",
@@ -58,25 +59,46 @@ export default [
58
59
  parserOptions: {
59
60
  ecmaVersion: "latest",
60
61
  sourceType: "module",
62
+ ecmaFeatures: {
63
+ jsx: true,
64
+ },
61
65
  },
62
66
  },
63
67
  },
64
68
 
65
- // Shared rules for all JS, TS and Vue files
69
+ // Prettier integration (replaces: extends: ["plugin:prettier/recommended"])
70
+ eslintPluginPrettierRecommended,
71
+
72
+ // eslint-config-prettier disables rules that conflict with Prettier —
73
+ // including `curly`, which Prettier never rewrites.
74
+ eslintConfigPrettier,
75
+
76
+ // Shared rules for all JS, TS, JSX, TSX and Vue files.
77
+ // MUST come after eslint-config-prettier: in flat config a later entry wins,
78
+ // so explicit rules such as `curly` would otherwise be silently switched off.
66
79
  {
67
- files: ["**/*.{js,mjs,cjs,ts,mts,cts,vue}"],
80
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx,vue,nvue}"],
68
81
  rules: {
69
- ...prettierRules,
70
82
  ...commonRules,
83
+ ...prettierRules,
84
+ },
85
+ },
86
+
87
+ // CommonJS files and config files legitimately need require()
88
+ {
89
+ files: ["**/*.cjs", "**/.*rc.js", "**/*.config.js"],
90
+ rules: {
91
+ "@typescript-eslint/no-require-imports": "off",
71
92
  },
72
93
  },
73
94
 
74
- // .nvue file handling (uni-app)
95
+ // .nvue file handling (uni-app) — mirrors the legacy config, which parses
96
+ // nvue script blocks as modules so `import` works.
75
97
  {
76
98
  files: ["**/*.nvue"],
77
99
  languageOptions: {
78
100
  parserOptions: {
79
- sourceType: "script",
101
+ sourceType: "module",
80
102
  },
81
103
  },
82
104
  },
@@ -12,26 +12,26 @@ export default [
12
12
  // Vue 3 essential rules
13
13
  ...pluginVue.configs["flat/essential"].map((config) => ({
14
14
  ...config,
15
- files: ["**/*.vue"],
15
+ files: ["**/*.{vue,nvue}"],
16
16
  })),
17
17
 
18
18
  // Vue plugin setup and custom overrides
19
19
  {
20
- files: ["**/*.vue"],
20
+ files: ["**/*.{vue,nvue}"],
21
21
  languageOptions: {
22
22
  parser: parserVue,
23
23
  parserOptions: {
24
24
  parser: tseslint.parser,
25
25
  sourceType: "module",
26
26
  ecmaVersion: "latest",
27
- extraFileExtensions: [".vue"],
27
+ extraFileExtensions: [".vue", ".nvue"],
28
28
  },
29
29
  },
30
30
  rules: {
31
31
  "vue/multi-word-component-names": "off",
32
32
  "@typescript-eslint/no-explicit-any": "off",
33
33
  "vue/no-mutating-props": ["error", { shallowOnly: true }],
34
- "vue/html-indent": ["error", 4],
34
+ "vue/html-indent": "off",
35
35
  "vue/script-indent": "off",
36
36
  "vue/html-self-closing": "off",
37
37
  "vue/max-attributes-per-line": "off",
@@ -41,15 +41,20 @@ export default [
41
41
 
42
42
  // .nvue specific overrides
43
43
  {
44
- files: ["*.nvue"],
44
+ files: ["**/*.nvue"],
45
45
  languageOptions: {
46
46
  parserOptions: {
47
- sourceType: "script",
47
+ sourceType: "module",
48
48
  },
49
49
  },
50
50
  rules: {
51
51
  "vue/comment-directive": "off",
52
+ // .nvue uses semicolons (see src/prettier/index.cjs), so the base
53
+ // `semi: ["error", "never"]` rule must be disabled here — mirrors
54
+ // the legacy config in src/eslint/vue3.cjs.
55
+ semi: "off",
56
+ // Prettier cannot infer a parser from the custom .nvue extension.
57
+ "prettier/prettier": ["error", { parser: "vue", semi: true }],
52
58
  },
53
59
  },
54
60
  ]
55
-
@@ -4,32 +4,40 @@ const base = require("./base.cjs")
4
4
  module.exports = {
5
5
  ...base,
6
6
  parser: "vue-eslint-parser",
7
- extends: [...base.extends, "plugin:vue/vue3-essential"],
7
+ extends: [...base.extends, "plugin:vue/essential"],
8
8
  parserOptions: {
9
9
  ...base.parserOptions,
10
10
  parser: "@typescript-eslint/parser",
11
- extraFileExtensions: [".vue"],
11
+ extraFileExtensions: [".vue", ".nvue"],
12
12
  },
13
13
  plugins: [...base.plugins, "vue"],
14
14
  overrides: [
15
15
  {
16
16
  env: { node: true },
17
- files: [".eslintrc.{js,cjs}", "*.nvue"],
17
+ files: [".eslintrc.{js,cjs}"],
18
18
  parserOptions: { sourceType: "script" },
19
19
  rules: { "vue/comment-directive": "off" },
20
20
  },
21
21
  ...(base.overrides || []),
22
+ {
23
+ files: ["**/*.nvue"],
24
+ parserOptions: { sourceType: "module" },
25
+ rules: {
26
+ "vue/comment-directive": "off",
27
+ semi: "off",
28
+ "prettier/prettier": ["error", { parser: "vue", semi: true }],
29
+ },
30
+ },
22
31
  ],
23
32
  rules: {
24
33
  ...base.rules,
25
34
  "vue/multi-word-component-names": "off",
26
35
  "@typescript-eslint/no-explicit-any": "off",
27
36
  "vue/no-mutating-props": ["error", { shallowOnly: true }],
28
- "vue/html-indent": ["error", 4],
37
+ "vue/html-indent": "off",
29
38
  "vue/script-indent": "off",
30
39
  "vue/html-self-closing": "off",
31
40
  "vue/max-attributes-per-line": "off",
32
41
  "vue/singleline-html-element-content-newline": "off",
33
42
  },
34
43
  }
35
-
package/src/gitignore ADDED
@@ -0,0 +1,11 @@
1
+ node_modules/
2
+ dist/
3
+ unpackage/
4
+ coverage/
5
+ *.local
6
+ *.log
7
+ .DS_Store
8
+ .idea/
9
+ .vscode/
10
+ *.tgz
11
+ .eslintcache
@@ -1,4 +1 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- npx --no-install commitlint --edit
1
+ npx --no-install commitlint --edit "${1}"
@@ -1,4 +1 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
1
  npx --no-install -- lint-staged
@@ -24,8 +24,7 @@ module.exports = {
24
24
  },
25
25
  {
26
26
  files: "*.nvue",
27
- options: { semi: true },
27
+ options: { parser: "vue", semi: true },
28
28
  },
29
29
  ],
30
30
  }
31
-
@@ -9,9 +9,17 @@ module.exports = {
9
9
  "stylelint-config-recess-order",
10
10
  ],
11
11
  plugins: ["stylelint-prettier"],
12
+ ignoreFiles: [
13
+ "**/node_modules/**",
14
+ "**/dist/**",
15
+ "**/coverage/**",
16
+ "**/public/**",
17
+ "**/assets/iconfont/**",
18
+ "**/*.min.css",
19
+ ],
12
20
  overrides: [
13
21
  {
14
- files: ["**/*.{vue,html}"],
22
+ files: ["**/*.{vue,nvue,html}"],
15
23
  customSyntax: "postcss-html",
16
24
  },
17
25
  {
@@ -51,5 +59,18 @@ module.exports = {
51
59
  "scss/comment-no-empty": null,
52
60
  "selector-class-pattern": null,
53
61
  "font-family-no-missing-generic-family-keyword": null,
62
+ // 现代 CSS 语法与选择器宽松放行
63
+ "selector-not-notation": null,
64
+ "import-notation": null,
65
+ "media-feature-range-notation": null,
66
+ "no-descending-specificity": null,
67
+ // 业务样式容错放行
68
+ "block-no-empty": null,
69
+ "scss/at-extend-no-missing-placeholder": null,
70
+ // 兼容混合 Less 及 Vue 内嵌 Less 语法,避免 stylelint-scss 规则解析崩溃或误报
71
+ "scss/operator-no-newline-after": null,
72
+ "scss/operator-no-newline-before": null,
73
+ "scss/operator-no-unspaced": null,
74
+ "scss/no-global-function-names": null,
54
75
  },
55
76
  }
@@ -8,9 +8,17 @@ module.exports = {
8
8
  "stylelint-config-recess-order",
9
9
  ],
10
10
  plugins: ["stylelint-prettier"],
11
+ ignoreFiles: [
12
+ "**/node_modules/**",
13
+ "**/dist/**",
14
+ "**/coverage/**",
15
+ "**/public/**",
16
+ "**/assets/iconfont/**",
17
+ "**/*.min.css",
18
+ ],
11
19
  overrides: [
12
20
  {
13
- files: ["**/*.{vue,html}"],
21
+ files: ["**/*.{vue,nvue,html}"],
14
22
  customSyntax: "postcss-html",
15
23
  },
16
24
  {
@@ -45,5 +53,12 @@ module.exports = {
45
53
  "no-duplicate-selectors": null,
46
54
  "selector-class-pattern": null,
47
55
  "font-family-no-missing-generic-family-keyword": null,
56
+ // 现代 CSS 语法与选择器宽松放行
57
+ "selector-not-notation": null,
58
+ "import-notation": null,
59
+ "media-feature-range-notation": null,
60
+ "no-descending-specificity": null,
61
+ // 业务样式容错放行
62
+ "block-no-empty": null,
48
63
  },
49
- }
64
+ }