@@ -9,15 +9,15 @@ Sorts imports alphabetically and case insensitive in ascending order.
9
9
10
10
Example of ** incorrect** code for this rule:
11
11
12
- ``` js
12
+ ``` javascript
13
13
import c from " c"
14
14
import b from " b"
15
15
import a from " a"
16
16
```
17
17
18
18
Example of ** correct** code for this rule:
19
19
20
- ``` js
20
+ ``` javascript
21
21
import a from " a"
22
22
import b from " b"
23
23
import c from " c"
@@ -28,6 +28,7 @@ import c from "c"
28
28
This rule has an object with its properties as:
29
29
30
30
- ` "groups" ` (default: ` [] ` )
31
+ - ` "separator" ` (default: ` "" ` )
31
32
32
33
### Groups
33
34
@@ -69,7 +70,7 @@ groups as well as a custom regex sort group.
69
70
70
71
This configuration would result in the following output.
71
72
72
- ``` js
73
+ ``` javascript
73
74
import " index.css"
74
75
import React from " react"
75
76
import { createStore } from " redux"
@@ -101,6 +102,48 @@ The configuration example above shows how this works where the static asset
101
102
imports are the second sort group even though they have the highest order and
102
103
are thus the last sort group in the resulting code.
103
104
105
+ ### Separator
106
+
107
+ You can customize the separator between sort groups using the ` separator `
108
+ option. By default, there is no separator but you can specify one or more
109
+ newlines between sort groups.
110
+
111
+ ``` json
112
+ {
113
+ "sort/imports" : [
114
+ " warn" ,
115
+ {
116
+ "groups" : [
117
+ { "type" : " side-effect" , "order" : 1 },
118
+ { "type" : " other" , "order" : 3 }
119
+ ],
120
+ "separator" : " \n "
121
+ }
122
+ ]
123
+ }
124
+ ```
125
+
126
+ This configuration would result in the following output.
127
+
128
+ ``` javascript
129
+ import " index.css"
130
+
131
+ import React from " react"
132
+ import { createStore } from " redux"
133
+ import c from " c"
134
+
135
+ import a from " ../a"
136
+ import b from " ./b"
137
+
138
+ import image1 from " my-library/static/image.svg"
139
+ import image2 from " static/image.jpg"
140
+ import image3 from " static/image.png"
141
+ ```
142
+
143
+ Note that the separator only applies if you have defined sort groups.
144
+ Additionally, extra newlines between imports in the _ same sort group_ will be
145
+ removed.
146
+
104
147
## When Not To Use It
105
148
106
149
This rule is a formatting preference and not following it won't negatively
0 commit comments