my-code-style 1.0.0 → 1.4.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.
package/README.md CHANGED
@@ -1,9 +1,14 @@
1
1
  # my-code-style
2
2
 
3
- Lint/Format/Git 配置工程化 npm 包。适用于 Vue 3 + TypeScript + uni-app 项目。
3
+ Lint/Format/Git 配置工程化 npm 包。适用于 Vue 3 + TypeScript + uni-app 项目及纯 Node/TS 基础工程。
4
4
 
5
5
  支持 ESLint v8 (.eslintrc.cjs) 和 ESLint v9 (Flat Config) 双格式,支持 SCSS 和 Less 样式检查。
6
6
 
7
+ ## 项目文档
8
+
9
+ - [HTML 项目技术全景](docs/project-overview.html):下载或克隆仓库后,用浏览器直接打开,查看项目结构、配置架构、接入流程与维护注意事项;支持离线阅读和打印。
10
+ - [Markdown 技术文档](TECHNICAL_DOC.md)
11
+
7
12
  ## 快速开始
8
13
 
9
14
  ```bash
@@ -11,23 +16,24 @@ pnpm add -D my-code-style
11
16
  npx my-code-style-init
12
17
  ```
13
18
 
14
- init 脚本会自动检测项目的 ESLint 版本和 CSS 预处理器,生成对应的配置文件。
19
+ init 脚本会自动检测项目技术栈类型(uni-app / Vue 3 / Node 基础库)、ESLint 版本和 CSS 预处理器,自动按需生成对应的配置文件。
15
20
 
16
21
  ## 生成的文件
17
22
 
18
- | 文件 | 说明 |
19
- |------|------|
20
- | `.eslintrc.cjs` | ESLint 配置(v8 项目,TypeScript + Vue 3 + uni-app) |
21
- | `eslint.config.ts` | ESLint Flat Config(v9 项目,TypeScript + Vue 3 + uni-app) |
22
- | `.prettierrc.cjs` | Prettier 格式化配置 |
23
- | `.prettierignore` | Prettier 忽略文件(跳过二进制文件) |
24
- | `.stylelintrc.cjs` | Stylelint CSS/SCSS/Less 配置 |
25
- | `.commitlintrc.cjs` | Git commit 信息规范 |
26
- | `.versionrc.js` | 自动版本号 + CHANGELOG 生成 |
27
- | `.editorconfig` | 编辑器基础配置 |
28
- | `.gitattributes` | Git 文件类型处理(统一 EOL=LF,标记二进制文件) |
29
- | `.husky/commit-msg` | Git hook: commitlint |
30
- | `.husky/pre-commit` | Git hook: lint-staged |
23
+ | 文件 | 说明 |
24
+ | ---------------------------------- | ----------------------------------------------------------------------------- |
25
+ | `.eslintrc.cjs` | ESLint 配置(v8 项目,TypeScript + Vue 3 / uni-app) |
26
+ | `eslint.config.mjs` | ESLint Flat Config(v9 项目,默认优先推荐) |
27
+ | `.prettierrc.cjs` | Prettier 格式化配置 |
28
+ | `.prettierignore` | Prettier 忽略文件(跳过二进制文件与产物) |
29
+ | `.stylelintrc.cjs` | Stylelint CSS/SCSS/Less 配置(非样式项目自动跳过) |
30
+ | `.commitlintrc.cjs` | Git commit 信息规范(支持智能 scope 猜测) |
31
+ | `.versionrc.js` / `.versionrc.cjs` | 自动版本号 + CHANGELOG(ESM 生成 `.versionrc.cjs`,CJS 生成 `.versionrc.js`) |
32
+ | `.editorconfig` | 编辑器基础配置 |
33
+ | `.gitattributes` | Git 文件类型处理(统一 EOL=LF,标记二进制文件) |
34
+ | `.gitignore` | Git 忽略文件(自动忽略 node_modules/、dist/、*.tgz 等) |
35
+ | `.husky/commit-msg` | Git hook: commitlint(Husky 9 格式) |
36
+ | `.husky/pre-commit` | Git hook: lint-staged(Husky 9 格式) |
31
37
 
32
38
  ## 手动使用(不通过 init)
33
39
 
@@ -38,18 +44,18 @@ init 脚本会自动检测项目的 ESLint 版本和 CSS 预处理器,生成
38
44
  module.exports = require("my-code-style/eslint/uniapp")
39
45
 
40
46
  // 或按需引入中间层
41
- const base = require("my-code-style/eslint") // 基础 TypeScript
42
- const vue3 = require("my-code-style/eslint/vue3") // + Vue 3 规则
47
+ const base = require("my-code-style/eslint") // 基础 TypeScript
48
+ const vue3 = require("my-code-style/eslint/vue3") // + Vue 3 规则
43
49
  ```
44
50
 
45
- ### ESLint v9 (Flat Config / eslint.config.ts)
51
+ ### ESLint v9 (Flat Config / eslint.config.mjs)
46
52
 
47
- ```ts
48
- // eslint.config.ts
53
+ ```js
54
+ // eslint.config.mjs
49
55
  import uniappConfig from "my-code-style/eslint/flat/uniapp"
50
56
 
51
57
  // 或按需引入中间层
52
- import baseConfig from "my-code-style/eslint/flat/base"
58
+ import baseConfig from "my-code-style/eslint/flat"
53
59
  import vue3Config from "my-code-style/eslint/flat/vue3"
54
60
  ```
55
61
 
@@ -65,7 +71,16 @@ module.exports = require("my-code-style/stylelint")
65
71
  // .commitlintrc.cjs
66
72
  const base = require("my-code-style/commitlint")
67
73
  const { generateScopes, guessCurrentScope } = require("my-code-style/commitlint/scopes")
68
- module.exports = { ...base, prompt: { ...base.prompt, scopes: generateScopes("src") } }
74
+ const scopeComplete = guessCurrentScope()
75
+ module.exports = {
76
+ ...base,
77
+ prompt: {
78
+ ...base.prompt,
79
+ customScopesAlign: !scopeComplete ? "top" : "bottom",
80
+ defaultScope: scopeComplete,
81
+ scopes: [...generateScopes("src"), "mock"],
82
+ },
83
+ }
69
84
 
70
85
  // .versionrc.js
71
86
  module.exports = require("my-code-style/versionrc")
@@ -87,32 +102,57 @@ module.exports = {
87
102
 
88
103
  ## 导出入口
89
104
 
90
- | 入口 | 说明 |
91
- |------|------|
92
- | `my-code-style` | 默认:ESLint v8 uni-app 配置 |
93
- | `my-code-style/eslint` | 基础 ESLint v8(TypeScript) |
94
- | `my-code-style/eslint/vue3` | + Vue 3 规则 |
95
- | `my-code-style/eslint/uniapp` | + uni-app globals |
96
- | `my-code-style/eslint/flat` | ESLint v9 Flat Config 基础 |
97
- | `my-code-style/eslint/flat/vue3` | + Vue 3 规则 |
98
- | `my-code-style/eslint/flat/uniapp` | + uni-app globals |
99
- | `my-code-style/prettier` | Prettier 配置 |
100
- | `my-code-style/stylelint` | Stylelint 配置(SCSS + Less) |
101
- | `my-code-style/stylelint/less-override` | Less 专用覆写配置 |
102
- | `my-code-style/commitlint` | Commitlint 基础配置 |
103
- | `my-code-style/commitlint/scopes` | 动态 scope 工具函数 |
104
- | `my-code-style/versionrc` | standard-version 配置 |
105
+ | 入口 | 说明 |
106
+ | --------------------------------------- | ----------------------------- |
107
+ | `my-code-style` | 默认:ESLint v8 uni-app 配置 |
108
+ | `my-code-style/eslint` | 基础 ESLint v8(TypeScript) |
109
+ | `my-code-style/eslint/vue3` | + Vue 3 规则 |
110
+ | `my-code-style/eslint/uniapp` | + uni-app globals |
111
+ | `my-code-style/eslint/flat` | ESLint v9 Flat Config 基础 |
112
+ | `my-code-style/eslint/flat/vue3` | + Vue 3 规则 |
113
+ | `my-code-style/eslint/flat/uniapp` | + uni-app globals |
114
+ | `my-code-style/prettier` | Prettier 配置 |
115
+ | `my-code-style/stylelint` | Stylelint 配置(SCSS / 默认) |
116
+ | `my-code-style/stylelint/less` | Less 专用 Stylelint 配置 |
117
+ | `my-code-style/stylelint/less-override` | Less 专用覆写配置 |
118
+ | `my-code-style/commitlint` | Commitlint 基础配置 |
119
+ | `my-code-style/commitlint/scopes` | 动态 scope 工具函数 |
120
+ | `my-code-style/versionrc` | standard-version 配置 |
121
+
122
+ ## CLI 初始化参数
123
+
124
+ ```bash
125
+ npx my-code-style-init [--dry-run] [--backup] [--version|-v] [--help|-h]
126
+ ```
127
+
128
+ - `--dry-run`:试运行模式,仅输出将执行的变更,不修改任何文件。
129
+ - `--backup`:在覆盖已有配置文件之前,将其备份到 `.my-code-style-backup/` 目录。
130
+ - 具备**事务回滚保护**:若在写入过程中遭遇文件权限或磁盘异常,自动回滚所有修改,恢复工作区原始状态。
105
131
 
106
132
  ## 特性
107
133
 
108
134
  - **双引号**:`quotes: ["error", "double", { avoidEscape: false, allowTemplateLiterals: true }]`
109
- - **4 空格缩进**:`tabWidth: 4`
135
+ - **4 空格缩进**:`tabWidth: 4`(由 Prettier 全权统一格式化)
110
136
  - **无分号**:`semi: false`(`.nvue` 文件除外)
111
137
  - **行宽 100**:`printWidth: 100`
112
- - **小程序适配**:允许 `rpx` 单位、`page` 标签、`::v-deep` 伪类
113
- - **uni-app globals**:`uni`、`UniApp`、`wx`、`getCurrentPages`
114
- - **Less 支持**:`postcss-less` 解析、`@` 变量放行、`::v-deep` 伪元素
115
- - **双 ESLint 格式**:v8 (.eslintrc.cjs) v9 (Flat Config) 自动检测
138
+ - **JSX / TSX 全面支持**:Flat Config 与传统配置均支持 `.jsx` 和 `.tsx` 语法解析、Prettier 格式化、规则修复与目录扫描
139
+ - **多工程形态适配**:智能识别 uni-app / Vue 3 / 纯 Node-TS 基础工程,无样式的纯代码项目自动跳过 Stylelint
140
+ - **双 ESLint 格式**:ESLint v9 (Flat Config,未配置项目默认优先) 与 v8 (.eslintrc.cjs) 全自动检测,强化支持 npm 别名、workspace 协议与复杂 semver 范围
141
+ - **现代化 Git Hooks**:采用 Husky 9 原生极简 hook + lint-staged 互斥文件分组,串行运行、消除并发写入缓存冲突
142
+ - **Stylelint SCSS、Less 及混合工程双支持**:支持纯 SCSS、纯 Less 以及两者共存的混合工程,放行 `@` 变量、小程序 `rpx`/`page`、深度选择器 `::v-deep` 及现代 CSS 伪类,组件内嵌多预处理器样式全面检查
143
+ - **严格暂存区 Scope 猜测**:`guessCurrentScope()` 严格只依据 Git 暂存区推断 scope,支持多目录频次投票、重命名、物理删除、中文路径与空格路径
144
+ - **ESM 兼容的自动版本发布**:支持 CommonJS(`.versionrc.js`)与 ESM(`.versionrc.cjs`)工程无缝对接 standard-version,一键版本递增与 CHANGELOG 生成
145
+
146
+ ## 测试套件
147
+
148
+ ```bash
149
+ npm test # 运行基础 CLI 与配置矩阵测试(52 项)
150
+ npm run test:integration:setup # 安装现代化隔离依赖运行环境
151
+ npm run test:integration # 运行 Flat Config、真实 Husky 及提交链路测试(44 项)
152
+ npm run test:legacy:setup # 安装 ESLint 8 隔离运行环境
153
+ npm run test:legacy # 运行 ESLint 8.57.0 兼容性回归测试(25 项)
154
+ npm run test:all # 全量运行全部 121 项测试
155
+ ```
116
156
 
117
157
  ## License
118
158