code-simplifier 1.0.0 → 1.2.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 +56 -1
- package/bin/code-simplifier.js +73 -1
- package/cypress.config.js +45 -0
- package/jest.config.js +46 -0
- package/lib/ai-auto-fix.js +829 -0
- package/lib/ai-code-review.js +705 -0
- package/lib/ai-knowledge-base.js +757 -0
- package/lib/ai-quality-analyzer.js +1095 -0
- package/lib/ai-refactor-advisor.js +853 -0
- package/lib/ai-trend-analyzer.js +674 -0
- package/lib/auto-fix.js +382 -0
- package/lib/eslint-integration.js +328 -0
- package/lib/git-hooks.js +353 -0
- package/lib/master.js +117 -0
- package/lib/multi-language-analyzer.js +397 -0
- package/lib/ralph-integration.js +541 -0
- package/package.json +87 -61
package/README.md
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
- **质量监控** - 实时监控代码质量指标
|
|
12
12
|
- **知识库管理** - 积累最佳实践和经验教训
|
|
13
13
|
- **自动更新** - 保持工具始终最新
|
|
14
|
-
- **多语言支持** -
|
|
14
|
+
- **多语言支持** - JavaScript、TypeScript、Python、Java、C#、C++、PHP、Go、Rust、Kotlin、Swift
|
|
15
|
+
- **ESLint 集成** - 自动运行 ESLint 分析和修复
|
|
16
|
+
- **Git 钩子** - 自动安装 pre-commit 和 pre-push 钩子
|
|
17
|
+
- **自动修复** - 智能修复常见代码问题
|
|
15
18
|
|
|
16
19
|
## 快速开始
|
|
17
20
|
|
|
@@ -153,6 +156,58 @@ npx code-simplifier update
|
|
|
153
156
|
npx code-simplifier update --force
|
|
154
157
|
```
|
|
155
158
|
|
|
159
|
+
### eslint - ESLint 代码分析
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# 运行 ESLint 分析
|
|
163
|
+
npx code-simplifier eslint
|
|
164
|
+
|
|
165
|
+
# 自动修复可修复的问题
|
|
166
|
+
npx code-simplifier eslint --fix
|
|
167
|
+
|
|
168
|
+
# 输出 JSON 格式
|
|
169
|
+
npx code-simplifier eslint --format json
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### hooks - Git 钩子管理
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# 交互式安装 Git 钩子
|
|
176
|
+
npx code-simplifier hooks
|
|
177
|
+
|
|
178
|
+
# 安装 pre-commit 和 pre-push 钩子
|
|
179
|
+
npx code-simplifier hooks --install
|
|
180
|
+
|
|
181
|
+
# 列出已安装的钩子
|
|
182
|
+
npx code-simplifier hooks --list
|
|
183
|
+
|
|
184
|
+
# 卸载钩子
|
|
185
|
+
npx code-simplifier hooks --uninstall
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### autofix - 自动修复
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# 自动修复代码问题
|
|
192
|
+
npx code-simplifier autofix
|
|
193
|
+
|
|
194
|
+
# 预览模式(不实际修改文件)
|
|
195
|
+
npx code-simplifier autofix --dry-run
|
|
196
|
+
|
|
197
|
+
# 指定目录
|
|
198
|
+
npx code-simplifier autofix --dir src
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### lang - 多语言分析
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# 分析项目中的多种语言
|
|
205
|
+
npx code-simplifier lang
|
|
206
|
+
|
|
207
|
+
# 指定目录
|
|
208
|
+
npx code-simplifier lang --dir src
|
|
209
|
+
```
|
|
210
|
+
|
|
156
211
|
## 配置文件
|
|
157
212
|
|
|
158
213
|
配置存储在 `.code-simplifier/config.json`:
|
package/bin/code-simplifier.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Code-Simplifier 持续改进系统
|
|
@@ -178,6 +178,78 @@ program
|
|
|
178
178
|
config.run(options)
|
|
179
179
|
})
|
|
180
180
|
|
|
181
|
+
// eslint命令
|
|
182
|
+
program
|
|
183
|
+
.command('eslint')
|
|
184
|
+
.description(chalk.red('🔍 ESLint 代码分析'))
|
|
185
|
+
.option('--fix', '自动修复可修复的问题', false)
|
|
186
|
+
.option('-f, --format <type>', '输出格式 (json|text)', 'json')
|
|
187
|
+
.action(async (options) => {
|
|
188
|
+
try {
|
|
189
|
+
const eslint = require('../lib/eslint-integration')
|
|
190
|
+
await eslint.runAnalysis('.', options)
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.error(chalk.red('❌ ESLint 分析失败:'), error.message)
|
|
193
|
+
process.exit(1)
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
// hooks命令
|
|
198
|
+
program
|
|
199
|
+
.command('hooks')
|
|
200
|
+
.description(chalk.yellow('🔧 Git 钩子管理'))
|
|
201
|
+
.option('--install', '安装 Git 钩子')
|
|
202
|
+
.option('--uninstall', '卸载 Git 钩子')
|
|
203
|
+
.option('--list', '列出已安装的钩子')
|
|
204
|
+
.action(async (options) => {
|
|
205
|
+
try {
|
|
206
|
+
const master = require('../lib/master')
|
|
207
|
+
await master.manageGitHooks(options)
|
|
208
|
+
} catch (error) {
|
|
209
|
+
console.error(chalk.red('❌ 钩子管理失败:'), error.message)
|
|
210
|
+
process.exit(1)
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
// autofix命令
|
|
215
|
+
program
|
|
216
|
+
.command('autofix')
|
|
217
|
+
.description(chalk.green('🔧 自动修复代码问题'))
|
|
218
|
+
.option('-d, --dir <path>', '检查目录', 'src')
|
|
219
|
+
.option('--dry-run', '预览模式,不实际修改文件', false)
|
|
220
|
+
.action(async (options) => {
|
|
221
|
+
try {
|
|
222
|
+
const autoFix = require('../lib/auto-fix')
|
|
223
|
+
const result = await autoFix.run(options)
|
|
224
|
+
console.log(chalk.green('\n✅ 自动修复完成'))
|
|
225
|
+
console.log(chalk.cyan(` 检测问题: ${result.totalIssues}`))
|
|
226
|
+
console.log(chalk.cyan(` 已修复: ${result.applied}`))
|
|
227
|
+
console.log(chalk.cyan(` 跳过: ${result.skipped}`))
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.error(chalk.red('❌ 自动修复失败:'), error.message)
|
|
230
|
+
process.exit(1)
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
// lang命令
|
|
235
|
+
program
|
|
236
|
+
.command('lang')
|
|
237
|
+
.description(chalk.cyan('🌐 多语言代码分析'))
|
|
238
|
+
.option('-d, --dir <path>', '检查目录', '.')
|
|
239
|
+
.action(async (options) => {
|
|
240
|
+
try {
|
|
241
|
+
const multiLang = require('../lib/multi-language-analyzer')
|
|
242
|
+
const result = await multiLang.analyze('.', options)
|
|
243
|
+
if (result.success) {
|
|
244
|
+
console.log(chalk.green('\n✅ 多语言分析完成'))
|
|
245
|
+
console.log(chalk.cyan(` 检测到 ${result.languages.length} 种语言`))
|
|
246
|
+
}
|
|
247
|
+
} catch (error) {
|
|
248
|
+
console.error(chalk.red('❌ 多语言分析失败:'), error.message)
|
|
249
|
+
process.exit(1)
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
|
|
181
253
|
// demo命令
|
|
182
254
|
program
|
|
183
255
|
.command('demo')
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { defineConfig } = require('cypress')
|
|
2
|
+
|
|
3
|
+
module.exports = defineConfig({
|
|
4
|
+
e2e: {
|
|
5
|
+
// 测试文件位置
|
|
6
|
+
specPattern: 'tests/e2e/**/*.cy.{js,jsx,ts,tsx}',
|
|
7
|
+
|
|
8
|
+
// 支持的文件类型
|
|
9
|
+
supportFile: 'tests/e2e/support/e2e.js',
|
|
10
|
+
|
|
11
|
+
// 测试结果和视频
|
|
12
|
+
videosFolder: 'tests/e2e/videos',
|
|
13
|
+
screenshotsFolder: 'tests/e2e/screenshots',
|
|
14
|
+
|
|
15
|
+
// 视口尺寸
|
|
16
|
+
viewportWidth: 1280,
|
|
17
|
+
viewportHeight: 720,
|
|
18
|
+
|
|
19
|
+
// 截图设置
|
|
20
|
+
screenshotOnRunFailure: true,
|
|
21
|
+
|
|
22
|
+
// 视频录制
|
|
23
|
+
video: false,
|
|
24
|
+
|
|
25
|
+
// 测试设置
|
|
26
|
+
defaultCommandTimeout: 10000,
|
|
27
|
+
requestTimeout: 10000,
|
|
28
|
+
responseTimeout: 10000,
|
|
29
|
+
|
|
30
|
+
// 环境变量
|
|
31
|
+
env: {
|
|
32
|
+
apiUrl: 'http://localhost:3000'
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// baseUrl(用于测试监控仪表板)
|
|
36
|
+
baseUrl: 'http://localhost:3000',
|
|
37
|
+
|
|
38
|
+
setupNodeEvents(on, config) {
|
|
39
|
+
// 实现 node 事件监听器
|
|
40
|
+
// 例如:cypress run --record
|
|
41
|
+
// 或 cypress open
|
|
42
|
+
return config
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
})
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
// 测试环境
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
|
|
5
|
+
// 测试文件匹配模式
|
|
6
|
+
testMatch: [
|
|
7
|
+
'<rootDir>/tests/unit/**/*.test.js',
|
|
8
|
+
'<rootDir>/tests/integration/**/*.test.js'
|
|
9
|
+
],
|
|
10
|
+
|
|
11
|
+
// 覆盖率收集
|
|
12
|
+
collectCoverage: true,
|
|
13
|
+
collectCoverageFrom: [
|
|
14
|
+
'lib/**/*.js',
|
|
15
|
+
'!lib/**/*.test.js',
|
|
16
|
+
'!lib/**/node_modules/**',
|
|
17
|
+
'!lib/**/*.md'
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
// 覆盖率报告格式
|
|
21
|
+
coverageReporters: ['text', 'lcov', 'html'],
|
|
22
|
+
|
|
23
|
+
// 输出目录
|
|
24
|
+
coverageDirectory: 'coverage',
|
|
25
|
+
|
|
26
|
+
// 覆盖率阈值(当前阶段的目标)
|
|
27
|
+
// 暂时禁用全局阈值,因为大多数模块尚未测试
|
|
28
|
+
// coverageThreshold 将在添加更多测试后启用
|
|
29
|
+
|
|
30
|
+
// 模块路径映射
|
|
31
|
+
moduleNameMapper: {
|
|
32
|
+
'^@/(.*)$': '<rootDir>/lib/$1'
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
// 设置文件
|
|
36
|
+
setupFilesAfterEnv: ['<rootDir>/tests/setup.js'],
|
|
37
|
+
|
|
38
|
+
// 清除模拟
|
|
39
|
+
clearMocks: true,
|
|
40
|
+
|
|
41
|
+
// 详细输出
|
|
42
|
+
verbose: true,
|
|
43
|
+
|
|
44
|
+
// 在测试之间清理模拟
|
|
45
|
+
restoreMocks: true
|
|
46
|
+
}
|