Skip to content

Commit 3b923b6

Browse files
committed
🔧 chore(feature): 添加impsort命令
1 parent ea5c282 commit 3b923b6

File tree

9 files changed

+260
-404
lines changed

9 files changed

+260
-404
lines changed

.eslintrc.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
"ecmaVersion": "latest"
1414
},
1515
"plugins": [
16-
"@typescript-eslint",
17-
"simple-import-sort"
16+
"@typescript-eslint"
1817
],
19-
"rules": {
20-
"simple-import-sort/imports": "error",
21-
"simple-import-sort/exports": "error"
22-
}
18+
"rules": {}
2319
}

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,47 @@ codeg format -p ./src -p ./components
329329

330330
PS: 依赖 `prettier` CLI 模式, 同时对项目配置的 `.prettierignore``.prettierrc.json` 生效.
331331

332+
## impsort 命令
333+
334+
运行 `eslint` 对模块导入进行分组&按字母排序, 支持命令模式, 询问模式和 API 模式;
335+
336+
### 命令模式
337+
338+
```bash
339+
# 尝试修复 src 文件夹中模块的导入顺序
340+
codeg impsort -p ./src
341+
342+
# 尝试修复 src 和 components 文件夹中模块的导入顺序
343+
codeg impsort -p ./src -p ./components
344+
```
345+
346+
| 选项 | 描述 |
347+
| ------------------------- | ------------ |
348+
| -p, --pattern \<pattern\> | 设置匹配规则 |
349+
350+
### 询问模式
351+
352+
```bash
353+
# 启动询问模式
354+
codeg impsort
355+
```
356+
357+
```
358+
# 询问过程
359+
1. 请选择需要尝试修复的文件/夹
360+
```
361+
362+
### API 模式
363+
364+
```typescript
365+
import { impSort } from "code-genius";
366+
367+
(async () => {
368+
await impSort(["./api-model/test.ts"]);
369+
})();
370+
```
371+
372+
PS: 依赖 `eslint` API 模式, 依赖 `simple-import-sort` 插件的同时依旧会读取项目配置的 `.eslintignore``.eslintrc.json` 文件.
332373
## 其他命令
333374

334375
| 命令 | 参数 | 默认值 | 功能描述 |

api-model/api-impsort.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { impSort } from "../src/index";
2+
3+
(async () => {
4+
await impSort(["./api-model/test.ts"]);
5+
})();

0 commit comments

Comments
 (0)