# fe-js-utils
前端代码质量检测 js 脚本工具

## 一、安装依赖
```bash
npm install fe-js-utils --save-dev
# 或
yarn add fe-js-utils -D
```

## 二、配置脚本命令
在 `package.json` 中添加以下 scripts：
```json
{
  "scripts": {
    "checkAny": "fe-js-utils checkAny",
    "cleanComments": "fe-js-utils cleanComments",
    "extractChinese": "fe-js-utils extractChinese"
  }
}
```

## 三、配置文件创建

### 步骤说明
1. 在项目根目录创建 `fe-js-utils.config.js`
2. 使用以下基础模板：
```javascript
// fe-js-utils.config.js
const path = require('path');

module.exports = {
  checkAny: {
    targetDir: './src',
    outputFile: path.join(process.cwd(), 'check-any-results.js'),
    skipSet: [],
    extFiles: ['.ts', '.vue']
  },
  cleanComments: {
    targetDir: './src',
    extFiles: ['.js', '.ts', '.vue']
  },
  extractChinese: {
    targetDir: './src',
    outputFile: path.join(process.cwd(), 'extract-chinese-results.js'),
    extFiles: ['.js', '.ts', '.vue'],
    excludeFiles: []
  }
};
```

## 四、工具及配置项说明

### 1. checkAny（Any类型检查）
**功能**：扫描项目中的 `any` 类型的使用
**使用场景**：
- 代码质量检查
- TypeScript类型规范审计

| 配置项     | 类型     | 默认值                                  | 说明                                                   |
| ---------- | -------- | --------------------------------------- | ------------------------------------------------------ |
| targetDir  | string   | './src'                                 | 需要扫描的源码目录                                     |
| outputFile | string   | `${process.cwd()}/check-any-results.js` | 结果输出文件路径                                       |
| skipSet    | string[] | []                                      | 需要跳过的代码模式（包含这些字符串的代码行将不被检测） |
| extFiles   | string[] | ['.ts', '.vue']                         | 需要扫描的文件扩展名                                   |

### 2. cleanComments（注释清理）
**功能**：清理无用的JSDoc注释  
**清理规则**：
- 自动清理`/** ... */`格式没有描述的`@param`及`@returns`

| 配置项    | 类型     | 默认值                 | 说明                   |
| --------- | -------- | ---------------------- | ---------------------- |
| targetDir | string   | './src'                | 需要清理注释的源码目录 |
| extFiles  | string[] | ['.js', '.ts', '.vue'] | 需要处理的文件扩展名   |

### 3. extractChinese（中文提取）
**功能**：提取项目中的中文字符
**使用场景**：
- 方便快速国际化的适配

| 配置项       | 类型     | 默认值                                               | 说明                 |
| ------------ | -------- | ---------------------------------------------------- | -------------------- |
| targetDir    | string   | './src'                                              | 需要扫描的源码目录   |
| outputFile   | string   | `${process.cwd()}/extract-chinese-results.js`        | 结果输出文件路径     |
| extFiles     | string[] | ['.js', '.jsx', '.ts', '.tsx', '.vue', '.html']      | 需要扫描的文件扩展名 |
| excludeDirs  | string[] | ['node_modules', 'dist', 'build', 'locales']         | 需要排除的目录       |
| excludeFiles | string[] | ['extract-chinese-results.js', 'extract-chinese.js'] | 需要排除的特定文件   |
| verbose      | boolean  | true                                                 | 是否显示处理过程日志 |

## TODO（待实现）
1. 入参超过2个没有定义成对象的
2. 有多个if else、以及if else 嵌套的
3. 没有被使用的引用定义
4. 检测项目中重复使用某一个字符串定义的地方
5. 魔法数字的检测，以及重复的魔法数字