Webpack plugin for code quality analysis and reporting
npm install @chiriwu-wjx/code-quality-pluginbash
npm install @chiriwu-wjx/code-quality-plugin --save-dev
`
使用方法
$3
`javascript
// webpack.config.js
const CodeQualityPlugin = require("@chiriwu-wjx/code-quality-plugin");
module.exports = {
// ... 其他配置
plugins: [new CodeQualityPlugin()]
};
`
$3
`javascript
// webpack.config.js
const CodeQualityPlugin = require("@chiriwu-wjx/code-quality-plugin");
module.exports = {
// ... 其他配置
plugins: [
new CodeQualityPlugin({
outputPath: "./reports/code-quality.json",
failOnError: true,
failOnWarning: false,
verbose: true,
includePatterns: ["*/.{js,ts,jsx,tsx}"],
excludePatterns: ["/node_modules/", "/dist/"],
maxComplexity: 8,
maxMaintainabilityIndex: 70
})
]
};
`
配置选项
| 选项 | 类型 | 默认值 | 描述 |
| ------------------------- | ---------- | ----------------------------------------------------- | ---------------------- |
| outputPath | string | ./code-quality-report.json | 报告输出路径 |
| failOnError | boolean | false | 发现错误时是否终止构建 |
| failOnWarning | boolean | false | 发现警告时是否终止构建 |
| verbose | boolean | true | 是否显示详细输出 |
| includePatterns | string[] | ['*/.{js,ts,jsx,tsx}'] | 包含的文件模式 |
| excludePatterns | string[] | ['/node_modules/', '/dist/', '/build/'] | 排除的文件模式 |
| maxComplexity | number | 10 | 最大圈复杂度 |
| maxMaintainabilityIndex | number | 65 | 最小可维护性指数 |
输出示例
$3
`
🔍 Code Quality Analysis Report
============================================================
📁 Files Analyzed: 15
📄 Total Lines: 1250
🔄 Cyclomatic Complexity: 45
📊 Maintainability Index: 78.5
📈 Halstead Volume: 234.7
🚨 Issues Summary:
Errors: 2
Warnings: 8
Info: 12
📋 Detailed Issues:
ERROR src/components/ComplexComponent.js:1:1 - Cyclomatic complexity (15) exceeds maximum (10)
WARNING src/utils/helper.js:45:1 - Line is too long (max 120 characters)
INFO src/constants.js:12:1 - Magic number detected: 1000
============================================================
`
$3
`json
{
"timestamp": "2024-01-15T10:30:00.000Z",
"metrics": {
"totalFiles": 15,
"totalLines": 1250,
"issues": [...],
"errorCount": 2,
"warningCount": 8,
"infoCount": 12,
"maintainabilityIndex": 78.5,
"cyclomaticComplexity": 45,
"halsteadVolume": 234.7
},
"summary": {
"status": "failed",
"totalIssues": 22,
"errorCount": 2,
"warningCount": 8,
"infoCount": 12
}
}
`
开发
`bash
安装依赖
pnpm install
构建
pnpm build
开发模式(监听文件变化)
pnpm dev
运行测试
pnpm test
代码检查
pnpm lint
``