organizeImports
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
assist/source/organizeImports¥Diagnostic Category:
assist/source/organizeImports -
建议执行此操作。
¥This action is recommended.
如何在编辑器中启用
Section titled “如何在编辑器中启用”¥How to enable in your editor
{ "editor.codeActionsOnSave": { "source.organizeImports.biome": "explicit", "source.fixAll.biome": "explicit" }}{ "code_actions_on_format": { "source.organizeImports.biome": true, "source.fixAll.biome": true }}source.organizeImports.biome ¥How to configure
{ "assist": { "actions": { "source": { "organizeImports": "on" } } }}¥Description
提供一个代码操作,用于使用内置或自定义顺序对文件中的导入和导出进行排序。
¥Provides a code action to sort the imports and exports in the file using a built-in or custom order.
导入和导出首先会被分成若干块,然后再进行排序。一个代码块的导入或导出随后会根据用户定义的组进行分组。在组内,导入项会根据导入/导出类型、导入/导出项是否具有属性以及导入源,按照内置顺序进行排序。在 JavaScript 生态系统中,source 也常被称为 specifier(说明符)。
¥Imports and exports are first separated into chunks, before being sorted. Imports or exports of a chunk are then grouped according to the user-defined groups. Within a group, imports are sorted using a built-in order that depends on the import/export kind, whether the import/export has attributes and the source being imported from. source is also often called specifier in the JavaScript ecosystem.
import A from "@my/lib" with { "attribute1": "value" };^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ kind source attributes
export * from "@my/lib" with { "attribute1": "value" };^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ kind source attributes导入块和导出块
Section titled “导入块和导出块”¥Chunk of imports and chunk of exports
代码块是一系列相邻的导入或导出。代码块仅包含导入或导出,不能同时包含两者。以下示例包含两个部分。第一个代码块包含三个导入语句,第二个代码块包含三个导出语句。
¥A chunk is a sequence of adjacent imports or exports. A chunk contains only imports or exports, not both at the same time. The following example includes two chunks. The first chunk consists of the three imports and the second chunk consists of the three exports.
// chunk 1import A from "a";import * as B from "b";import { C } from "c";// chunk 2export * from "d";export * as F from "e";export { F } from "f";代码块在遇到语句或副作用导入(也称为裸导入)时结束。每个副作用导入都构成一个独立的代码块。以下示例包含六个部分:
¥Chunks also end as soon as a statement or a side-effect import (also called bare import) is encountered. Every side-effect import forms an independent chunk. The following example contains six chunks:
// chunk 1import A from "a";import * as B from "b";// chunk 2import "x";// chunk 3import "y";// chunk 4import { C } from "c";// chunk 5export * from "d";function f() {}// chunk 6export * as E from "e";export { F } from "f";-
第一个代码块包含前两个
import,并以第一个副作用导入语句import "x"的出现结束。¥The first chunk contains the two first
importand ends with the appearance of the first side-effect importimport "x". -
第二个代码块仅包含副作用导入
import "x"。¥The second chunk contains only the side-effect import
import "x". -
第三个代码块仅包含副作用导入
import "y"。¥The third chunk contains only the side-effect import
import "y". -
第四个代码块包含一个
import;第一个export结束了它。¥The fourth chunk contains a single
import; The firstexportends it. -
第五个代码块包含第一个
export;函数声明结束了它。¥The fifth chunk contains the first
export; The function declaration ends it. -
第六个代码块包含最后两个
export。¥The sixth chunk contains the last two
export.
代码块也由独立注释分隔。独立注释是指注释后跟一个空行。未以空行结尾的注释是附加注释。请注意,在对导入和导出进行分块时,空行不会被考虑在内。以下示例包含一条独立的注释,将导入语句拆分为两个部分:
¥Chunks are also delimited by detached comments. A detached comment is a comment followed by a blank line. Comments not followed by a blank line are attached comments. Note that blank lines alone are not taken into account when chunking imports and exports. The following example contains a detached comment that splits the imports into two chunks:
// Attached comment 1import A from "a";
// Attached comment 2import * as B from "b";// Detached comment
import { C } from "c";import { C } from "c" 行构成第二个代码块。前两个导入语句之间的空行会被忽略,因此它们构成一个单独的代码块。
¥The line import { C } from "c" forms the second chunk.
The blank line between the first two imports is ignored so they form a single chunk.
排序器确保各个代码块之间用空行分隔。仅允许相邻的多个导入语句之间不使用空行分隔。以下代码…
¥The sorter ensures that chunks are separated from each other with blank lines. Only side-effect imports adjacent to a chunk of imports are not separated by a blank line. The following code…
import A from "a";import * as B from "b";import "x";import { C } from "c";export * from "d";// Detached comment
export * as F from "e";// Attached commentexport { F } from "f";排序方式如下:
¥is sorted as:
import A from "a";import * as B from "b";import "x";import { C } from "c";
export * from "d";
// Detached comment
export * as F from "e";// Attached commentexport { F } from "f";此外,请注意,代码块内的空行会被忽略并保留。可以通过显式定义分组来移除它们,如下一节所示。
¥Also, note that blank lines inside a chunk are ignored and preserved. They can be removed by explicitly defining groups as demonstrated in the next section.
导入和导出排序
Section titled “导入和导出排序”¥Import and export sorting
一旦形成代码块,每个代码块的导入和导出都会被排序。导入和导出按其来源排序。源按 “distance” 排序。当前模块的 “farther” 源位于顶部,用户看到的 “closer” 源位于底部。这将导致以下顺序:
¥Once chunks are formed, imports and exports of each chunk are sorted. Imports and exports are sorted by their source. Sources are ordered by “distance”. Sources that are “farther” from the current module are put on the top, sources “closer” to the user are put on the bottom. This leads to the following order:
-
类似
https://example.org的 URL¥URLs such as
https://example.org. -
支持
node:path、bun:test、jsr:@my?lib或npm:lib等协议的包。¥Packages with a protocol such as
node:path,bun:test,jsr:@my?lib, ornpm:lib. -
例如
mylib或@my/lib之类的包。¥Packages such as
mylibor@my/lib. -
别名:以
@/、#、~、$或%开头的 source。它们通常是 Node.js 子路径导入 或 TypeScript 路径别名。¥Aliases: sources starting with
@/,#,~,$, or%. They usually are Node.js subpath imports or TypeScript path aliases. -
绝对路径和相对路径。
¥Absolute and relative paths.
使用针对 URL、包和路径定制的 自然排序 格式,对具有相同源类别的两个导入/导出进行排序。值得注意的是,此顺序确保 A < a < B < b 生效。排序方式也考虑了编号,例如 a9 < a10。
¥Two imports/exports with the same source category are sorted using a natural sort order tailored to URLs, packages, and paths.
Notably, the order ensures that A < a < B < b.
The order takes also numbers into account, e.g. a9 < a10.
例如,以下代码……
¥For example, the following code…
import sibling from "./file.js";import internal from "#alias";import fs from "fs";import { test } from "node:test";import path from "node:path";import parent from "../parent.js";import scopedLibUsingJsr from "jsr:@scoped/lib";import data from "https://example.org";import lib from "lib";import scopedLib from "@scoped/lib";……排序如下:
¥…is sorted as follows:
import data from "https://example.org";import scopedLibUsingJsr from "jsr:@scoped/lib";import path from "node:path";import { test } from "node:test";import scopedLib from "@scoped/lib";import fs from "fs";import lib from "lib";import internal from "#alias";import parent from "../parent.js";import sibling from "./file.js";如果两个导入或导出共享同一个源且位于同一个代码块中,则它们将按类型排序,如下所示:
¥If two imports or exports share the same source and are in the same chunk, then they are ordered according to their kind as follows:
-
命名空间类型导入 / 命名空间类型导出
¥Namespace type import / Namespace type export
-
默认类型导入
¥Default type import
-
命名类型导入 / 命名类型导出
¥Named type import / Named type export
-
命名空间导入 / 命名空间导出
¥Namespace import / Namespace export
-
合并默认导入和命名空间导入
¥Combined default and namespace import
-
默认导入
¥Default import
-
合并默认导入和命名导入
¥Combined default and named import
-
命名导入 / 命名导出
¥Named import / Named export
带有属性的导入和导出始终排在最前面。例如,以下代码……
¥Imports and exports with attributes are always placed first. For example, the following code…
import * as namespaceImport from "same-source";import type * as namespaceTypeImport from "same-source";import type { namedTypeImport } from "same-source";import defaultNamespaceCombined, * as namespaceCombined from "same-source";import defaultNamedCombined, { namedCombined } from "same-source";import defaultImport from "same-source";import type defaultTypeImport from "same-source";import { importWithAttribute } from "same-source" with { "attribute": "value" } ;排序方式如下:
¥is sorted as follows:
import { importWithAttribute } from "same-source" with { "attribute": "value" } ;import type * as namespaceTypeImport from "same-source";import type defaultTypeImport from "same-source";import type { namedTypeImport } from "same-source";import * as namespaceImport from "same-source";import defaultNamespaceCombined, * as namespaceCombined from "same-source";import defaultImport from "same-source";import defaultNamedCombined, { namedCombined } from "same-source";此默认顺序无法更改。然而,用户仍然可以使用分组的概念自定义导入和导出的排序方式,如下一节所述。
¥This default order cannot be changed. However, users can still customize how imports and exports are sorted using the concept of groups as explained in the following section.
导入和导出分组
Section titled “导入和导出分组”¥Import and export groups
一个代码块的导入或导出会被分成多个组,然后按照上一节中描述的内置顺序进行排序。默认情况下,每个数据块都包含一个组。这些默认分组及其顺序可能不符合你的喜好。排序器提供了一个 groups 选项,允许你自定义代码块的分组方式。groups 选项是一个组匹配器列表。组匹配器为:
¥Imports or exports of a chunk are divided into groups before being sorted with the built-in order described in the previous section.
By default every chunk consists of a single group.
These default groups and their order may not be to your taste.
The sorter provides a groups option that allows you to customize how the chunks are divided into groups.
The groups option is a list of group matchers.
A group matcher is:
-
预定义的组匹配器,或者
¥A predefined group matcher, or
-
全局模式,或
¥A glob pattern, or
-
对象匹配器,或
¥An object matcher, or
-
glob 模式、预定义组匹配器和对象匹配器列表。
¥A list of glob patterns, predefined group matchers, and object matchers.
预定义的组匹配器是 CONSTANT_CASE 中的字符串,其前缀和后缀均为 :。排序器提供了几个预定义的分组匹配器:
¥Predefined group matchers are strings in CONSTANT_CASE prefixed and suffixed by :.
The sorter provides several predefined group matchers:
-
:ALIAS::以#、@/、~、$或%开头的 source。¥
:ALIAS:: sources starting with#,@/,~,$, or%. -
:BUN::以协议bun:开头或对应于内置 Bun 模块(例如bun)的 source。¥
:BUN:: sources starting with the protocolbun:or that correspond to a built-in Bun module such asbun. -
:NODE::以协议node:开头或对应于内置 Node.js 模块(例如fs或path)的 source。¥
:NODE:: sources starting with the protocolnode:or that correspond to a built-in Node.js module such asfsorpath. -
:PACKAGE::作用域包和裸包。¥
:PACKAGE:: scoped and bare packages. -
:PACKAGE_WITH_PROTOCOL::带有协议的作用域包和裸包。¥
:PACKAGE_WITH_PROTOCOL:: scoped and bare packages with a protocol. -
:PATH::绝对路径和相对路径。¥
:PATH:: absolute and relative paths. -
:URL::以https://和http://开头的 source。¥
:URL:: sources starting withhttps://andhttp://.
举个例子。在默认配置中,不使用 node: 协议的 Node.js 模块与使用协议的模块是分开的。要将它们分组在一起,你可以使用预定义的组 :NODE:。给定以下配置…
¥Let’s take an example.
In the default configuration, Node.js modules without the node: protocol are separated from those with a protocol.
To group them together, you can use the predefined group :NODE:.
Given the following configuration…
{ "assist": { "actions": { "source": { "organizeImports": { "level": "on", "options": { "groups": [ ":URL:", ":NODE:" ] } } } } }}……以及以下代码……
¥…and the following code…
import sibling from "./file.js";import internal from "#alias";import fs from "fs";import { test } from "node:test";import path from "node:path";import parent from "../parent.js";import scopedLibUsingJsr from "jsr:@scoped/lib";import data from "https://example.org";import lib from "lib";import scopedLib from "@scoped/lib";……最终我们得到以下排序结果,其中 node:path 和 fs Node.js 模块的导入被分组在一起:
¥…we end up with the following sorted result where the imports of node:path and the fs Node.js module are grouped together:
import data from "https://example.org";import fs from "fs";import path from "node:path";import { test } from "node:test";import scopedLibUsingJsr from "jsr:@scoped/lib";import scopedLib from "@scoped/lib";import lib from "lib";import internal from "#alias";import parent from "../parent.js";import sibling from "./file.js";请注意,所有不匹配任何组匹配器的导入始终放置在末尾。
¥Note that all imports that don’t match a group matcher are always placed at the end.
分组匹配器也可以是 glob 模式和 glob 模式列表。Glob 模式会选择源与模式匹配的导入和导出。在以下示例中,我们创建两个组:一个收集源文件以 @my/lib 开头的导入/导出项(@my/lib/special 除外),另一个收集源文件以 @/ 开头的导入/导出项。
¥Group matchers can also be glob patterns and list of glob patterns.
Glob patterns select imports and exports with a source that matches the pattern.
In the following example, we create two groups: one that gathers imports/exports with a source starting with @my/lib except @my/lib/special and the other that gathers imports/exports starting with @/.
{ "options": { "groups": [ ["@my/lib", "@my/lib/**", "!@my/lib/special", "!@my/lib/special/**"], "@/**" ] }}将此配置应用于以下代码……
¥By applying this configuration to the following code…
import lib from "@my/lib";import aliased from "@/alias";import path from "@my/lib/special";import test from "@my/lib/path";……我们得到以下排序结果。源为 @my/lib 和 @my/lib/path 的导入构成第一组。它们分别匹配 glob 模式 @my/lib 和 @my/lib/**。源为 @my/lib/special 的导入语句不会被放入第一个组中,因为它被异常 !@my/lib/special 拒绝。源为 @/alias 的导入语句会被放入第二个组中,因为它匹配了 glob 模式 @/**。最后,其他导入语句将被放在末尾。
¥…we obtain the following sorted result.
Imports with the sources @my/lib and @my/lib/path form the first group.
They match the glob patterns @my/lib and @my/lib/** respectively.
The import with the source @my/lib/special is not placed in this first group because it is rejected by the exception !@my/lib/special.
The import with the source @/alias is placed in a second group because it matches the glob pattern @/**.
Finally, other imports are placed at the end.
import lib from "@my/lib";import test from "@my/lib/path";import aliased from "@/alias";import path from "@my/lib/special";请注意,@my/lib 匹配 @my/lib,但不匹配 @my/lib/**。反之,@my/lib/subpath 与 @my/lib/** 匹配,但不与 @my/lib 匹配。因此,如果你想要接受所有以 @my/lib 开头的导入/导出语句,则必须同时指定两个 glob 模式。前缀 ! 表示例外情况。你可以通过在异常后使用常规 glob 模式来创建异常的异常。例如,["@my/lib", "@my/lib/**", "!@my/lib/special", "!@my/lib/special/**", "@my/lib/special/*/accepted/**"] 允许你接受所有与 @my/lib/special/*/accepted/** 匹配的源。请注意,预定义组也可以被否定。!:NODE: 匹配所有不匹配 :NODE: 的源文件。有关支持的 glob 模式的更多详细信息,请参阅相关章节。
¥Note that @my/lib matches @my/lib but not @my/lib/**.
Conversely, @my/lib/subpath matches @my/lib/**, but not @my/lib.
So, you have to specify both glob patterns if you want to accept all imports/exports that start with @my/lib.
The prefix ! indicates an exception.
You can create exceptions of exceptions by following an exception by a regular glob pattern.
For example ["@my/lib", "@my/lib/**", "!@my/lib/special", "!@my/lib/special/**", "@my/lib/special/*/accepted/**"] allows you to accepts all sources matching @my/lib/special/*/accepted/**.
Note that the predefined groups can also be negated. !:NODE: matches all sources that don’t match :NODE:.
For more details on the supported glob patterns, see the dedicated section.
最后,分组匹配器可以同时是对象匹配器。对象匹配器允许仅匹配类型导入和导出。
¥Finally, group matchers can be object matchers. An object matcher allows to match type-only imports and exports.
给定以下配置:
¥Given the following configuration:
{ "options": { "groups": [ { "type": false, "source": ["@my/lib", "@my/lib/**"] }, ["@my/lib", "@my/lib/**"] ] }}以下代码:
¥The following code:
import type { T } from "@my/lib";import { V } from "@my/lib";排序方式如下:
¥is sorted as follows:
import { V } from "@my/lib";import type { T } from "@my/lib";对象匹配器 { "type": false, "source": ["@my/lib", "@my/lib/**"] } 匹配不包含 type 关键字且源匹配列表 ["@my/lib", "@my/lib/**"] 中某个 glob 模式的导入和导出。
¥The object matcher { "type": false, "source": ["@my/lib", "@my/lib/**"] } match against imports and exports without the type keyword with a source that matches one of the glob pattern of the list ["@my/lib", "@my/lib/**"].
排序程序允许使用预定义字符串 :BLANK_LINE: 以空行分隔两个组。给定以下配置…
¥The sorter allows the separation of two groups with a blank line using the predefined string :BLANK_LINE:.
Given the following configuration…
{ "options": { "groups": [ [":BUN:", ":NODE:"], ":BLANK_LINE:", ["@my/lib", "@my/lib/**", "!@my/lib/special", "!@my/lib/special/**"], "@/**" ] }}……以下代码……
¥…the following code…
import test from "bun:test";import path from "node:path";import lib from "@my/lib";import libPath from "@my/lib/path";import libSpecial from "@my/lib/special";import aliased from "@/alias";……排序如下:
¥…is sorted as:
import path from "node:path";
import lib from "@my/lib";import test from "@my/lib/path";import aliased from "@/alias";import path from "@my/lib/special";分组按顺序匹配。这意味着一个组匹配器可以覆盖后续的组。例如,在以下配置中,组匹配器 :URL: 永远不会匹配,因为所有导入和导出都匹配第一个匹配器 **。
¥Groups are matched in order.
This means that one group matcher can shadow succeeding groups.
For example, in the following configuration, the group matcher :URL: is never matched because all imports and exports match the first matcher **.
{ "options": { "groups": [ "**", ":URL:" ] }}¥Comment handling
在对导入和导出进行排序时,附加的注释会随导入或导出一起移动,而分离的注释(注释后跟一个空行)则保留在原位。
¥When sorting imports and exports, attached comments are moved with their import or export, and detached comments (comments followed by a blank line) are left where they are.
但是,凡事皆有例外。如果注释出现在文件顶部,即使后面没有空行,也会被视为分离注释。这确保版权声明和文件头注释始终位于文件顶部。
¥However, there is an exception to the rule. If a comment appears at the top of the file, it is considered as detached even if no blank line follows. This ensures that copyright notice and file header comments stay at the top of the file.
例如,以下代码……
¥For example, the following code…
// Copyright notice and file header commentimport F from "f";// Attached comment for `e`import E from "e";// Attached comment for `d`import D from "d";// Detached comment (new chunk)
// Attached comment for `b`import B from "b";// Attached comment for `a`import A from "a";……排序如下。头部注释后会自动添加一个空行,以确保附加的注释不会与头部注释合并。
¥…is sorted as follows. A blank line is automatically added after the header comment to ensure that the attached comment doesn’t merge with the header comment.
// Copyright notice and file header comment
// Attached comment for `d`import D from "d";// Attached comment for `e`import E from "e";import F from "f";
// Detached comment (new chunk)
// Attached comment for `a`import A from "a";// Attached comment for `b`import B from "b";导入和导出合并
Section titled “导入和导出合并”¥Import and export merging
整理器还会合并可以合并的导入和导出。
¥The organizer also merges imports and exports that can be merged.
例如,以下代码:
¥For example, the following code:
import type { T1 } from "package";import type { T2 } from "package";import * as ns from "package";import D1 from "package";import D2 from "package";import { A } from "package";import { B } from "package";合并方式如下:
¥is merged as follows:
import type { T1, T2 } from "package";import D1, * as ns from "package";import D2, { A, B } from "package";命名导入、命名导出和属性排序
Section titled “命名导入、命名导出和属性排序”¥Named imports, named exports and attributes sorting
排序器还会对命名导入、命名导出以及属性进行排序。它使用自然排序顺序来比较数字。
¥The sorter also sorts named imports, named exports, as well as attributes. It uses a natural sort order for comparing numbers.
以下代码…
¥The following code…
import { a, b, A, B, c10, c9 } from "a";
export { a, b, A, B, c10, c9 } from "a";
import special from "special" with { "type": "ty", "metadata": "data" };……排序如下:
¥…is sorted as follows:
import { A, a, B, b, c9, c10 } from "a";
export { A, a, B, b, c9, c10 } from "a";
import special from "special" with { "metadata": "data", "type": "ty" };支持的 glob 模式
Section titled “支持的 glob 模式”¥Supported glob patterns
你需要了解源代码的结构才能知道哪个源代码与 glob 匹配。源被分成多个源段。每个源段都由分隔符 / 或源的起始/结束位置分隔。例如,src/file.js 由两个源段组成:src 和 file.js。
¥You need to understand the structure of a source to understand which source matches a glob.
A source is divided in source segments.
Every source segment is delimited by the separator / or the start/end of the source.
For instance src/file.js consists of two source segments: src and file.js.
-
匹配 source 段内零个或多个字符的星号
*。¥star
*that matches zero or more characters inside a source segment
file.js 与 *.js 匹配。反之,src/file.js 与 *.js 不匹配
¥file.js matches *.js.
Conversely, src/file.js doesn’t match *.js
-
匹配零个或多个源段
**的 globstar**必须由分隔符/或 glob 的开头/结尾括起来。例如,**a不是一个有效的 glob 模式。此外,**后面不能再跟其他 glob 星号。例如,**/**不是一个有效的 glob 模式。¥globstar
**that matches zero or more source segments**must be enclosed by separators/or the start/end of the glob. For example,**ais not a valid glob. Also,**must not be followed by another globstar. For example,**/**is not a valid glob.
file.js 和 src/file.js 匹配 ** 和 **/*.js。反之,README.txt 不匹配 **/*.js,因为源以 .txt 结尾。
¥file.js and src/file.js match ** and **/*.js
Conversely, README.txt doesn’t match **/*.js because the source ends with .txt.
-
使用
\*转义*。¥Use
\*to escape*
\* 匹配源文件中的字面字符 *。
¥\* matches the literal * character in a source.
-
?、[、]、{和}必须使用\进行转义。这些字符保留以供将来可能使用。¥
?,[,],{, and}must be escaped using\. These characters are reserved for possible future use. -
使用
!作为首字符来否定通配符。¥Use
!as first character to negate a glob
file.js 与 !*.test.js 匹配。src/file.js 匹配 !*.js,因为源代码包含多个段。
¥file.js matches !*.test.js.
src/file.js matches !*.js because the source contains several segments.
¥Common configurations
本节提供了一些常见配置示例。
¥This section provides some examples of common configurations.
将 import type 和 export type 放在代码块开头
Section titled “将 import type 和 export type 放在代码块开头”¥Placing import type and export type at the start of the chunks
{ "options": { "groups": [ { "type": true } ] }}请注意,你可能需要使用 lint 规则 useImportType 及其 style 来强制使用 import type 而不是 import { type }。
¥Note that you may want to use the lint rule useImportType and its style to enforce the use of import type instead of import { type }.
将 import type 和 export type 放在代码块末尾
Section titled “将 import type 和 export type 放在代码块末尾”¥Placing import type and export type at the end of the chunks
{ "options": { "groups": [ { "type": false } ] }}将导入标识符的排序方式更改为字典序排序
Section titled “将导入标识符的排序方式更改为字典序排序”¥Change the sorting of import identifiers to lexicographic sorting
此选项仅适用于已命名的导入/导出,而不适用于源代码本身。
¥This only applies to the named import/exports and not the source itself.
{ "assist": { "actions": { "source": { "organizeImports": { "options": { "identifierOrder": "lexicographic" } } } } }}import { var1, var2, var21, var11, var12, var22 } from 'my-package'code-block.js:1:1 assist/source/organizeImports FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The imports and exports are not sorted.
> 1 │ import { var1, var2, var21, var11, var12, var22 } from ‘my-package’
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Organize Imports (Biome)
1 │ - import·{·var1,·var2,·var21,·var11,·var12,·var22·}·from·‘my-package’
1 │ + import·{·var1,·var11,·var12,·var2,·var21,·var22·}·from·‘my-package’
2 2 │
将导入标识符的排序方式更改为逻辑排序
Section titled “将导入标识符的排序方式更改为逻辑排序”¥Change the sorting of import identifiers to logical sorting
如果你不进行覆盖,则为默认行为。此选项仅适用于已命名的导入/导出,而不适用于源代码本身。
¥This is the default behavior in case you do not override. This only applies to the named import/exports and not the source itself.
{ "assist": { "actions": { "source": { "organizeImports": { "options": { "identifierOrder": "natural" } } } } }}import { var1, var2, var21, var11, var12, var22 } from 'my-package'code-block.js:1:1 assist/source/organizeImports FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The imports and exports are not sorted.
> 1 │ import { var1, var2, var21, var11, var12, var22 } from ‘my-package’
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Organize Imports (Biome)
1 │ - import·{·var1,·var2,·var21,·var11,·var12,·var22·}·from·‘my-package’
1 │ + import·{·var1,·var2,·var11,·var12,·var21,·var22·}·from·‘my-package’
2 2 │
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号