prettier-plugin-sort 0.1.1 → 1.0.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.zh.md CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  一个专注于排序的 [Prettier](https://prettier.io/) 插件。
4
4
 
5
- - 排序 JS / TS 文件里的 import 语句
6
- - 排序 `export { … }` 花括号内的命名导出
7
- - 排序 package.json 的顶层字段、字符串数组和依赖表
8
- - 零运行时依赖
5
+ - 排序 JavaScript、TypeScript Flow 中的顶层 `import` 和 `export { ... }`
6
+ - 排序 `package.json` 字段
9
7
 
10
8
  使用其他语言阅读:[English](./README.md) | 中文
11
9
 
12
10
  ## 安装
13
11
 
12
+ 需要 Prettier 3.9 或更高版本。
13
+
14
14
  ```shell
15
15
  npm i -D prettier prettier-plugin-sort
16
16
  ```
17
17
 
18
- 在 Prettier 配置里启用:
18
+ 在 Prettier 配置中启用插件:
19
19
 
20
20
  ```json
21
21
  {
@@ -23,24 +23,56 @@ npm i -D prettier prettier-plugin-sort
23
23
  }
24
24
  ```
25
25
 
26
- 然后按常规方式运行 Prettier 即可,例如 `npx prettier --write .`。
26
+ ## 作用范围
27
+
28
+ ES 模块排序支持以下 Prettier 解析器:
29
+
30
+ - `babel`
31
+ - `babel-flow`
32
+ - `babel-ts`
33
+ - `typescript`
34
+ - `flow`
35
+ - `acorn`
36
+ - `espree`
37
+ - `meriyah`
38
+
39
+ 上述排序同样适用于这些解析器处理的**嵌入式**代码,例如 Vue 或 Markdown 中的 JavaScript 或 TypeScript 内容。
40
+
41
+ 插件只处理 ES 模块语法。CommonJS 的 `require()`、`module.exports` 和 TypeScript `export =` 会保持不变。
42
+
43
+ `package.json` 排序支持以下 Prettier 解析器:
44
+
45
+ - `json`
46
+ - `json-stringify`
47
+
48
+ 仅当文件名为 `package.json` 时,才会启用排序。
27
49
 
28
- ## 当前支持的排序
50
+ ## 配置项
51
+
52
+ | 配置项 | 类型 | 默认值 | 作用 |
53
+ | ------------------------ | ----------------- | ------------------------------------------------------- | --------------------------------------------------- |
54
+ | `esmImportSort` | `boolean` | `true` | 分组并排序顶层静态 `import`,同时排列其中的具名导入 |
55
+ | `esmImportGroups` | `ImportGroup[]` | `["builtin", "external", "parent", "sibling", "index"]` | 指定 `import` 分组顺序 |
56
+ | `esmImportSeparation` | `boolean` | `true` | 在不同分组之间及副作用 `import` 的上下两侧留出空行 |
57
+ | `esmImportTypeStyle` | `TypeImportStyle` | `"separate"` | 控制仅类型 `import` 的写法与顺序 |
58
+ | `esmImportMerge` | `boolean` | `true` | 安全合并来自同一模块的 `import` |
59
+ | `esmExportSpecifierSort` | `boolean` | `true` | 按名称排列 `export { ... }` 形式的导出列表 |
60
+ | `packageSort` | `boolean` | `true` | 排序 `package.json` 字段 |
29
61
 
30
- ### import
62
+ ## `import` 排序
31
63
 
32
- #### 模块分组与排序
64
+ 插件会分组并排序文件顶层的静态 `import`,同时排列其中的具名导入。带 `as` 的具名导入按本地名称排序。
33
65
 
34
- 默认配置下,效果大致如下。
66
+ 插件不会处理动态 `import()`,也不会处理字符串和注释中类似 `import` 的内容。将 `esmImportSort` 设为 `false`,可以关闭所有 `import` 排序功能。
67
+
68
+ 插件会把分散在其他顶层语句之间的静态 `import` 集中到第一条 `import` 所在位置,再进行排序。
35
69
 
36
70
  排序前:
37
71
 
38
72
  <!-- prettier-ignore -->
39
73
  ```typescript
40
- import App from './App.tsx';
74
+ import App from './App';
41
75
  import fs from 'node:fs';
42
- import lodash from 'lodash';
43
- import path from 'node:path';
44
76
  import react from 'react';
45
77
  ```
46
78
 
@@ -48,51 +80,35 @@ import react from 'react';
48
80
 
49
81
  ```typescript
50
82
  import fs from 'node:fs';
51
- import path from 'node:path';
52
83
 
53
- import lodash from 'lodash';
54
84
  import react from 'react';
55
85
 
56
- import App from './App.tsx';
86
+ import App from './App';
57
87
  ```
58
88
 
59
- import 的模块一般可以按其来源分为不同的类别,例如上面的示例代码,'node:fs' 就属于 builtin 分类,该分类涵盖 Node.js 和 Bun **运行时**的内置模块。而像 react 和 lodash 这种直接从 npm 下载的依赖模块,属于 external 分类。
89
+ ### 分组
60
90
 
61
- 插件会先根据不同的模块进行分类,然后在模块内部基于字母顺序进行排列。
91
+ `esmImportGroups` 支持以下分组:
62
92
 
63
- 整体分组和排序方式参考了 [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) 的 [import/order](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md) 规则。
93
+ | 分组 | 匹配范围 |
94
+ | ---------- | ------------------------------------------- |
95
+ | `builtin` | 以 `node:`、`bun:` 开头的模块,以及 `bun` |
96
+ | `external` | 第三方包,以及没有匹配其他分组的模块路径 |
97
+ | `internal` | 以 `/`、`~`、`@/` 或 `#` 开头的模块路径 |
98
+ | `parent` | `../utils` 这类指向上级目录的相对路径 |
99
+ | `sibling` | `./Button` 这类指向同级目录的相对路径 |
100
+ | `index` | `.`、`./`、`./index` 及带扩展名的 `./index` |
64
101
 
65
- 插件 import 默认的配置是:
102
+ 现代 Node.js 代码应使用 [`node:` URL](https://nodejs.org/api/esm.html#node-imports) 显式引用内置模块。本插件也只把带 `node:` 前缀的 Node.js 内置模块归入 `builtin`。`fs`、`path` 等未带前缀的内置模块名称归入 `external`。
66
103
 
67
- ```json
68
- {
69
- "plugins": ["prettier-plugin-sort"],
70
- "importOrderGroups": ["builtin", "external", "parent", "sibling", "index"],
71
- "importOrderSeparation": true,
72
- "importOrderTypeImports": "separate",
73
- "importOrderMergeDuplicates": true
74
- }
75
- ```
76
-
77
- 各分组的匹配规则如下:
78
-
79
- | 分组 | 匹配内容 | 示例 |
80
- | ---------- | ---------------------------------------------------- | ---------------------------------- |
81
- | `builtin` | `node:*`、`bun:*`、`bun`,以及无前缀的 Node 内置模块 | `node:fs`、`path`、`bun` |
82
- | `external` | npm 包,以及不属于其他分组的模块 | `react`、`@scope/pkg` |
83
- | `internal` | 项目绝对路径与别名 | `/utils`、`~/app`、`@/shared` |
84
- | `parent` | 向上跳级的相对路径 | `../Button` |
85
- | `sibling` | 同级相对路径(不包含 index) | `./Icon` |
86
- | `index` | 当前目录的 index 模块 | `.`、`./`、`./index`、`./index.ts` |
104
+ 插件会移除配置数组中的重复项,并按默认顺序追加未列出的默认分组。默认配置不包含 `internal`,因此它在未显式加入时排在最后。
87
105
 
88
- > **关于 `internal` 的检测方式:** 插件目前通过说明符的前缀硬编码(`/`、`~`、`@/`)来判断,不会读取 tsconfig `paths` 或任何构建工具的配置。后续版本可能会提供 `importOrderInternalPatterns` 选项,支持自定义正则匹配。
89
-
90
- 你可以通过 `importOrderGroups` 调整分组顺序,或者删掉不需要的分组,比如把 `internal` 显式加入分组:
106
+ 项目使用上述路径别名时,可以手动加入 `internal`:
91
107
 
92
108
  ```json
93
109
  {
94
110
  "plugins": ["prettier-plugin-sort"],
95
- "importOrderGroups": [
111
+ "esmImportGroups": [
96
112
  "builtin",
97
113
  "external",
98
114
  "internal",
@@ -103,129 +119,40 @@ import 的模块一般可以按其来源分为不同的类别,例如上面的
103
119
  }
104
120
  ```
105
121
 
106
- 排序前:
107
-
108
- <!-- prettier-ignore -->
109
- ```typescript
110
- import App from './App.tsx';
111
- import react from 'react';
112
- import shared from '@/shared';
113
- ```
114
-
115
- 排序后:
116
-
117
- <!-- prettier-ignore -->
118
- ```typescript
119
- import react from 'react';
120
-
121
- import shared from '@/shared';
122
-
123
- import App from './App.tsx';
124
- ```
125
-
126
- 如果不想在分组之间插入空行,把 `importOrderSeparation` 设为 `false` 即可。
127
-
128
- #### 类型导入
129
-
130
- 默认配置下,插件会把 `type` import 拆成独立的语句。
122
+ 插件不会读取 `compilerOptions.paths`,也不会解析构建工具的别名配置。
131
123
 
132
- 排序前:
124
+ 如果不希望不同分组之间及副作用 `import` 的上下两侧留出空行,可以将 `esmImportSeparation` 设为 `false`。
133
125
 
134
- <!-- prettier-ignore -->
135
- ```typescript
136
- import { useState, type FC } from 'react';
137
- ```
126
+ ### 仅类型 `import` 写法
138
127
 
139
- 排序后:
128
+ `esmImportTypeStyle` 用来控制仅类型 `import` 的写法,共有四种取值:
140
129
 
141
- <!-- prettier-ignore -->
142
- ```typescript
143
- import type { FC } from 'react';
144
- import { useState } from 'react';
145
- ```
146
-
147
- `importOrderTypeImports` 的几种风格则参考了 ESLint 生态里对 type import 的常见约定,尤其是
148
- [@typescript-eslint/consistent-type-imports](https://typescript-eslint.io/rules/consistent-type-imports) 的 `fixStyle` 设计。
149
-
150
- 以 `import { c, type B, a } from 'mod';` 为例,各模式的效果:
151
-
152
- | 模式 | 结果 |
130
+ | 配置值 | 输入 `import { c, type B, a } from 'mod'` 后的结果 |
153
131
  | -------------- | ---------------------------------------------------------------- |
154
132
  | `separate` | `import type { B } from 'mod';`<br>`import { a, c } from 'mod';` |
155
133
  | `inline-first` | `import { type B, a, c } from 'mod';` |
156
134
  | `inline-last` | `import { a, c, type B } from 'mod';` |
157
135
  | `mixed` | `import { a, type B, c } from 'mod';` |
158
136
 
159
- `separate`、`inline-first`、`inline-last` 三种模式会先按类型和值分开,然后在各自组内按字母序排列。`mixed` 将统一按字母序排列(不分类型与值),type 关键字始终跟随它所修饰的标识符,保持原有的关系。
160
-
161
- #### 合并同源导入
162
-
163
- 默认情况下,来自同一来源的多条 import 语句会被合并成一条,便于阅读。
164
-
165
- 排序前:
166
-
167
- <!-- prettier-ignore -->
168
- ```typescript
169
- import { useState } from 'react';
170
- import { useEffect } from 'react';
171
- ```
172
-
173
- 排序后:
174
-
175
- ```typescript
176
- import { useEffect, useState } from 'react';
177
- ```
178
-
179
- `importOrderMergeDuplicates` 只负责合并这一步,花括号内的排列方式完全由 `importOrderTypeImports` 决定。比如把 `import { useState } from 'react';` 和 `import { type FC, useEffect } from 'react';` 合并后,不同模式的结果:
180
-
181
- - `separate`(默认):合并后这一阶段又会被拆回两条,最终保持独立的 `import type` 语句
182
- - `inline-first`:`import { type FC, useEffect, useState } from 'react';`
183
- - `inline-last`:`import { useEffect, useState, type FC } from 'react';`
184
- - `mixed`:`import { type FC, useEffect, useState } from 'react';`
185
-
186
- 如果你希望保留原本分离的两条语句,把 `importOrderMergeDuplicates` 设为 `false` 即可。副作用导入(`import 'mod';`)因为顺序有语义,永远不会被合并。
187
-
188
- #### 副作用导入
189
-
190
- 副作用导入(`import 'mod'`)的顺序通常有运行时语义,例如 CSS 的层叠顺序、polyfill 必须在框架之前加载等。插件不会跨越副作用导入移动其他 import 语句:
191
-
192
- 排序前:
137
+ 默认值为 `separate`。包含默认导入或命名空间导入的仅类型 `import` 会保留原有形式。
193
138
 
194
- <!-- prettier-ignore -->
195
- ```typescript
196
- import Button from './Button';
197
- import App from './App';
198
- import 'normalize.css';
199
- import theme from './theme';
200
- import Icon from './Icon';
201
- ```
139
+ ### 合并与排序边界
202
140
 
203
- 排序后:
141
+ 启用 `esmImportMerge` 后,来自同一模块的 `import` 会在安全的情况下合并。
204
142
 
205
- ```typescript
206
- import App from './App';
207
- import Button from './Button';
143
+ 当 `import` 属性不同、注释无法安全移动,或者默认导入和命名空间导入存在冲突时,插件不会合并这些 `import`。副作用 `import` 也不会合并。
208
144
 
209
- import 'normalize.css';
145
+ 排序不会跨越以下边界:
210
146
 
211
- import Icon from './Icon';
212
- import theme from './theme';
213
- ```
147
+ - 副作用 `import` 的顺序可能影响 CSS 层叠或兼容性补丁的加载,因此不会参与排序。它们会保持相对位置,并分隔前后的排序片段。
148
+ - 带有 `prettier-ignore` 的声明保持不变,其前后的 `import` 分别排序。
149
+ - 独立注释会分隔前后的 `import`。紧跟某条 `import` 的注释会和它一起移动。
150
+ - 插件会保留文件开头的 `#!` 指令、Prettier 文件级指令和位置敏感的 ESLint 指令。
151
+ - `import source`、`import defer`、Flow `import typeof` 等特殊声明可以整体参与排序。插件不会改写或合并这些声明。
214
152
 
215
- 副作用导入两侧的 import 各自独立排序,副作用导入本身保持原位不动。
153
+ ## `export` 排序
216
154
 
217
- 排序规则:
218
-
219
- - import 按分组分类,分组内按字母序排列
220
- - 默认分组顺序:`builtin` → `external` → `parent` → `sibling` → `index`
221
- - 分组之间默认插入空行,可通过 `importOrderSeparation` 关闭
222
- - `type` import 默认拆成独立语句,可通过 `importOrderTypeImports` 调整为内联
223
- - 同一来源的多条 import 默认合并为一条,可通过 `importOrderMergeDuplicates` 关闭
224
- - 副作用导入(`import 'mod'`)其顺序有语义,不会被移动,两侧的 import 各自独立排序
225
-
226
- ### export
227
-
228
- 默认情况下,`export { … }` 花括号内的命名导出会按字母序排列。
155
+ `esmExportSpecifierSort` 会按名称排列顶层 `export { ... }` 和 `export type { ... }`。使用 `as` 时,按导出后的名称排序。
229
156
 
230
157
  排序前:
231
158
 
@@ -240,17 +167,11 @@ export { useState, useEffect, type FC } from 'react';
240
167
  export { type FC, useEffect, useState } from 'react';
241
168
  ```
242
169
 
243
- 插件只整理花括号内的顺序,不会改变整条 export 语句的位置,也不会合并两条同来源的 export。如果不需要这个行为,把 `exportOrder` 设为 `false` 即可。
244
-
245
- 排序规则:
170
+ 插件不会移动或合并 `export` 声明。花括号内含有注释时,整条声明会保持原样,避免改变注释归属。
246
171
 
247
- - `export { … }` 和 `export type { … }` 花括号内的命名导出按字母序排列
248
- - 不改变整条 export 语句在文件中的位置
249
- - 不合并同来源的多条 export 语句
172
+ ## `package.json` 排序
250
173
 
251
- ### package.json
252
-
253
- 默认配置下,效果大致如下。
174
+ `package.json` 的字段顺序遵循 [sort-package-json 4.0.0 的默认规则](https://github.com/keithamus/sort-package-json/blob/v4.0.0/defaultRules.md)。`scripts`、`exports` 和依赖字段等内部内容也按该版本的规则排序。
254
175
 
255
176
  排序前:
256
177
 
@@ -258,11 +179,10 @@ export { type FC, useEffect, useState } from 'react';
258
179
  ```json
259
180
  {
260
181
  "version": "1.0.0",
261
- "keywords": ["sort", "prettier", "plugin"],
262
- "name": "demo",
182
+ "name": "example",
263
183
  "dependencies": {
264
- "typescript": "^6.0.0",
265
- "prettier": "^3.0.0"
184
+ "typescript": "^7.0.0",
185
+ "prettier": "^3.9.0"
266
186
  }
267
187
  }
268
188
  ```
@@ -271,65 +191,20 @@ export { type FC, useEffect, useState } from 'react';
271
191
 
272
192
  ```json
273
193
  {
274
- "name": "demo",
194
+ "name": "example",
275
195
  "version": "1.0.0",
276
- "keywords": ["plugin", "prettier", "sort"],
277
196
  "dependencies": {
278
- "prettier": "^3.0.0",
279
- "typescript": "^6.0.0"
197
+ "prettier": "^3.9.0",
198
+ "typescript": "^7.0.0"
280
199
  }
281
200
  }
282
201
  ```
283
202
 
284
- `package.json` 顶层字段顺序参考了 [sort-package-json](https://github.com/keithamus/sort-package-json) 维护的字段列表,便于和社区里被广泛使用的排序习惯保持一致。
285
-
286
- 排序规则:
287
-
288
- - 顶层字段按常用顺序排列(`name` → `version` → ... → `dependencies`)
289
- - 顶层的纯字符串数组按字母序排列,如 `keywords`、`files`
290
- - `dependencies`、`devDependencies`、`peerDependencies` 等依赖表永远按字母序排列,即使 `packageJsonOrder` 设为 `false` 也不例外。因为 `npm install` 每次都会按照字母序写回
291
- - `scripts`、`exports`、`imports` 等嵌套对象不会递归排序,它们的键顺序有运行时语义
292
- - 想让某些顶层字段完全跳过排序,可以在 `packageJsonOrderExcludeKeys` 里列出
293
-
294
- ## 配置项
295
-
296
- Prettier 的插件选项是扁平的,所以这些配置都以 `importOrder`、`exportOrder` 或 `packageJsonOrder` 开头。
297
-
298
- | 配置项 | 说明 | 默认值 |
299
- | ----------------------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------- |
300
- | `importOrder` | 是否排序 JS / TS 里的 import | `true` |
301
- | `importOrderGroups` | 分组顺序,支持 `builtin`、`external`、`internal`、`parent`、`sibling`、`index` | `["builtin", "external", "parent", "sibling", "index"]` |
302
- | `importOrderSeparation` | 分组之间是否插入空行 | `true` |
303
- | `importOrderTypeImports` | `type` import 的处理方式:`separate`、`inline-first`、`inline-last`、`mixed` | `"separate"` |
304
- | `importOrderMergeDuplicates` | 是否合并同来源的多条 import 语句(副作用导入除外) | `true` |
305
- | `exportOrder` | 是否按字母序排列 `export { … }` 花括号内的命名导出 | `true` |
306
- | `packageJsonOrder` | 是否排序 package.json 的顶层字段和字符串数组 | `true` |
307
- | `packageJsonOrderExcludeKeys` | 不参与 package.json 排序的顶层字段 | `[]` |
308
-
309
- ## 示例
310
-
311
- ```json
312
- {
313
- "plugins": ["prettier-plugin-sort"],
314
- "importOrderGroups": [
315
- "builtin",
316
- "external",
317
- "internal",
318
- "parent",
319
- "sibling",
320
- "index"
321
- ],
322
- "importOrderTypeImports": "inline-last",
323
- "packageJsonOrderExcludeKeys": ["contributes"]
324
- }
325
- ```
326
-
327
- ## 类型提示
203
+ `packageSort` 设为 `false` 只会关闭字段排序,Prettier 仍会照常排版该文件。
328
204
 
329
- 如果你在 `.ts` 或 `.js` 配置文件里写 Prettier 配置,可以直接复用插件导出的
330
- `SortOptions` 类型,这样写配置时会有补全和校验。
205
+ ## TypeScript 配置
331
206
 
332
- ### `.ts` 文件里使用
207
+ 插件同时导出 `SortOptions`、`ImportGroup` `TypeImportStyle`,可用于 TypeScript 配置文件:
333
208
 
334
209
  ```typescript
335
210
  import { type Config } from 'prettier';
@@ -337,7 +212,7 @@ import { type SortOptions } from 'prettier-plugin-sort';
337
212
 
338
213
  export default {
339
214
  plugins: ['prettier-plugin-sort'],
340
- importOrderGroups: [
215
+ esmImportGroups: [
341
216
  'builtin',
342
217
  'external',
343
218
  'internal',
@@ -345,47 +220,6 @@ export default {
345
220
  'sibling',
346
221
  'index',
347
222
  ],
348
- importOrderTypeImports: 'inline-last',
349
- packageJsonOrderExcludeKeys: ['contributes'],
223
+ esmImportTypeStyle: 'inline-last',
350
224
  } satisfies Config & SortOptions;
351
225
  ```
352
-
353
- ### 在 `.js` 文件里使用
354
-
355
- ```js
356
- /** @type {import('prettier').Config & import('prettier-plugin-sort').SortOptions} */
357
- const config = {
358
- plugins: ['prettier-plugin-sort'],
359
- importOrderGroups: [
360
- 'builtin',
361
- 'external',
362
- 'internal',
363
- 'parent',
364
- 'sibling',
365
- 'index',
366
- ],
367
- importOrderTypeImports: 'inline-last',
368
- packageJsonOrderExcludeKeys: ['contributes'],
369
- };
370
-
371
- export default config;
372
- ```
373
-
374
- 如果你只想单独复用字面量类型,也可以使用插件导出的 `ImportGroup` 和
375
- `TypeImportsStyle`。
376
-
377
- ## 项目由来
378
-
379
- 在接触 Prettier 之前,我一直都在使用 IDE 的自定义代码排序。因为后面开始尝试各种不同的 IDE,所以便有了统一配置管理的需求,于是将 ESLint + Prettier 引入到了项目中。
380
-
381
- 可是 Prettier 没有提供 sort 配置,我想要格式化 import 排序,就必须安装 `prettier-plugin-organize-imports` 插件,想要格式化 package.json 排序,就必须安装 `prettier-plugin-packagejson` 插件,导致体验十分割裂。
382
-
383
- 我在很长的一段时间里都没有去在意这些细枝末节,主要的精力放在了开发上。但在最近,我有调整 import type 内联排版的需求,发现 `prettier-plugin-organize-imports` 并不支持。再加上基于 `sort-package-json` 开发的 `prettier-plugin-packagejson` 有很多对于插件而言冗余的依赖项,所以便有了自己开发的打算。
384
-
385
- `prettier-plugin-sort` 的目的不是为了替代谁,而是让开发者有着更多的选择。Prettier 绝大多数的用途都是格式化 JS/TS 代码,而所有的 JS 项目都有着 package.json,所以 `prettier-plugin-sort` 只实现了这两种基础的排序,初衷是让 JS 开发者能够以最小的心智负担做到开箱即用(未来可能还会添加对 tsconfig.json 的排序支持)。如果你有着其它代码的排序要求,那么依然可以选择安装 `prettier-plugin-css-order` 之类的插件,它们之间并不冲突。
386
-
387
- ## 鸣谢
388
-
389
- - `eslint-plugin-import`: https://github.com/import-js/eslint-plugin-import
390
- - `typescript-eslint`: https://github.com/typescript-eslint/typescript-eslint
391
- - `sort-package-json`: https://github.com/keithamus/sort-package-json
package/dist/index.d.ts CHANGED
@@ -1,28 +1,5 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
- import { Plugin, SupportOptions } from 'prettier';
4
-
5
- /** import 分组,参考 eslint-plugin-import import/order 规则。 */
6
- export type ImportGroup = "builtin" | "external" | "internal" | "parent" | "sibling" | "index";
7
- /** `import type` 内联风格,参考 @typescript-eslint/consistent-type-imports 的 fixStyle 选项。 */
8
- export type TypeImportsStyle = "separate" | "inline-first" | "inline-last" | "mixed";
9
- /** 插件排序配置。 */
10
- export interface SortOptions {
11
- importOrder?: boolean;
12
- importOrderGroups?: ImportGroup[];
13
- importOrderSeparation?: boolean;
14
- importOrderTypeImports?: TypeImportsStyle;
15
- importOrderMergeDuplicates?: boolean;
16
- exportOrder?: boolean;
17
- packageJsonOrder?: boolean;
18
- packageJsonOrderExcludeKeys?: string[];
19
- }
20
- /** 向 Prettier 注册的选项。使用功能名词前缀命名,因为 Prettier API 不支持嵌套选项对象。 */
21
- export declare const options: SupportOptions;
22
- declare const plugin: Plugin;
23
-
24
- export {
25
- plugin as default,
26
- };
27
-
28
- export {};
1
+ import { type Plugin } from 'prettier';
2
+ declare const sortPlugin: Plugin;
3
+ export default sortPlugin;
4
+ export { options } from './options';
5
+ export type { ImportGroup, SortOptions, TypeImportStyle } from './options';