Skip to content

Commit 188f2c6

Browse files
authored
Update README.md
1 parent 503c4ba commit 188f2c6

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
11
# codegenius-impsort-plugin
2-
运行 eslint 对模块导入进行分组&按字母排序
2+
3+
运行 `eslint` 对模块导入进行分组&按字母排序, 支持命令模式, 询问模式和 API 模式;
4+
5+
使用场景: 用于通过 `simple-import-sort` 插件来对导入模块进行排序且未直接配置插件到 `.eslintrc` 情况.
6+
7+
### 命令模式
8+
9+
```bash
10+
# 尝试修复 src 文件夹中模块的导入顺序
11+
codeg impsort -p ./src
12+
13+
# 尝试修复 src 和 components 文件夹中模块的导入顺序
14+
codeg impsort -p ./src -p ./components
15+
```
16+
17+
| 选项 | 描述 |
18+
| ------------------------- | ------------ |
19+
| -p, --pattern \<pattern\> | 设置匹配规则 |
20+
| -a, --ask | 启用询问模式 |
21+
22+
### 询问模式
23+
24+
```bash
25+
# 启动询问模式
26+
codeg impsort --ask
27+
```
28+
29+
```
30+
# 询问过程
31+
1. 请选择需要尝试修复的文件/夹
32+
```
33+
34+
### API 模式
35+
36+
```typescript
37+
import { impSort } from "../src/index";
38+
39+
(async () => {
40+
await impSort(["./src"]);
41+
})();
42+
```
43+
44+
PS: 依赖 `eslint` API 模式, 依赖 `simple-import-sort` 插件的同时依旧会读取项目配置的 `.eslintignore``.eslintrc.json` 文件, 使用 `impsort` 的同时将同步进行 `fix` 检测和修复.
45+
46+
### 配置文件
47+
48+
```typescript
49+
# 覆盖默认的 `impsort` 配置
50+
import { defineConfig } from "code-genius";
51+
52+
export default defineConfig({
53+
commands: {
54+
format: {
55+
impsort: ["./src", "./scripts"],
56+
},
57+
},
58+
});
59+
```
60+
61+

0 commit comments

Comments
 (0)