@1adybug/prettier-plugin-sort-imports 0.0.24 → 0.0.26
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/dist/index.d.ts +35 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
import { Plugin } from "prettier";
|
|
2
|
-
import type { PluginConfig } from "./types";
|
|
1
|
+
import { Plugin, Options as PrettierOptions } from "prettier";
|
|
2
|
+
import type { GetGroupFunction, GroupSeparatorFunction, PluginConfig, SortGroupFunction, SortImportContentFunction, SortImportStatementFunction } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
|
+
export interface Options extends PrettierOptions {
|
|
5
|
+
/**
|
|
6
|
+
* 分组之间的分隔符,支持字符串或函数返回。
|
|
7
|
+
* @default undefined
|
|
8
|
+
*/
|
|
9
|
+
groupSeparator?: string | GroupSeparatorFunction;
|
|
10
|
+
/**
|
|
11
|
+
* 是否对副作用导入进行排序。
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
sortSideEffect?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 是否删除未使用的导入。
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
removeUnusedImports?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* 自定义获取分组名称。
|
|
22
|
+
*/
|
|
23
|
+
getGroup?: GetGroupFunction;
|
|
24
|
+
/**
|
|
25
|
+
* 自定义分组排序逻辑。
|
|
26
|
+
*/
|
|
27
|
+
sortGroup?: SortGroupFunction;
|
|
28
|
+
/**
|
|
29
|
+
* 自定义导入语句排序逻辑。
|
|
30
|
+
*/
|
|
31
|
+
sortImportStatement?: SortImportStatementFunction;
|
|
32
|
+
/**
|
|
33
|
+
* 自定义导入内容排序逻辑。
|
|
34
|
+
*/
|
|
35
|
+
sortImportContent?: SortImportContentFunction;
|
|
36
|
+
}
|
|
4
37
|
/** 创建自定义配置的插件(工厂函数) */
|
|
5
38
|
export declare function createPlugin(config?: PluginConfig): Plugin;
|
|
6
39
|
/** 默认插件实例(用于简单使用) */
|
package/dist/index.js
CHANGED
|
@@ -79,10 +79,10 @@ function removeUnusedImportsFromStatements(importStatements, code) {
|
|
|
79
79
|
}
|
|
80
80
|
return filteredStatements;
|
|
81
81
|
}
|
|
82
|
-
function formatImportStatement(statement, trailingComma
|
|
82
|
+
function formatImportStatement(statement, trailingComma) {
|
|
83
83
|
const { path, isExport, isSideEffect, importContents, leadingComments, trailingComments, removedTrailingComments, emptyLinesAfterComments } = statement;
|
|
84
84
|
const lines = [];
|
|
85
|
-
const shouldAddTrailingComma = "
|
|
85
|
+
const shouldAddTrailingComma = (trailingComma ?? "all") !== "none";
|
|
86
86
|
if (leadingComments && leadingComments.length > 0) {
|
|
87
87
|
lines.push(...leadingComments);
|
|
88
88
|
const emptyLines = emptyLinesAfterComments ?? 0;
|