Skip to content

Commit 4b26875

Browse files
authored
Merge pull request #45 from mskelton/import-separator
Import separators
2 parents e5a3793 + 057ac91 commit 4b26875

23 files changed

+1305
-2611
lines changed

.eslintrc

+2-17
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,13 @@
99
"prettier"
1010
],
1111
"env": {
12-
"es6": true,
1312
"node": true
1413
},
1514
"rules": {
16-
"@typescript-eslint/explicit-module-boundary-types": "off",
1715
"@typescript-eslint/no-non-null-assertion": "off",
1816
"@typescript-eslint/no-unused-vars": [
1917
"error",
20-
{
21-
"argsIgnorePattern": "^_"
22-
}
18+
{ "argsIgnorePattern": "^_" }
2319
]
24-
},
25-
"overrides": [
26-
{
27-
"files": "**/__tests__/**",
28-
"env": {
29-
"jest": true
30-
},
31-
"rules": {
32-
"@typescript-eslint/no-var-requires": "off"
33-
}
34-
}
35-
]
20+
}
3621
}

__mocks__/isomorphic-resolve.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default function resolve(source) {
2+
if (!source.startsWith("dependency-")) {
3+
throw new Error(`Cannot resolve "${source}"`)
4+
}
5+
}

docs/rules/destructuring-properties.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ insensitive in ascending order.
1010

1111
Examples of **incorrect** code for this rule:
1212

13-
```js
13+
```javascript
1414
let { b, c, a } = {}
1515
let { C, b } = {}
1616
let { b: a, a: b } = {}
1717
```
1818

1919
Examples of **correct** code for this rule:
2020

21-
```js
21+
```javascript
2222
let { a, b, c } = {}
2323
let { b, C } = {}
2424
let { a: b, b: a } = {}

docs/rules/export-members.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Sorts export members alphabetically and case insensitive in ascending order.
99

1010
Examples of **incorrect** code for this rule:
1111

12-
```js
12+
```javascript
1313
export { b, c, a } from "a"
1414
export { C, b } from "a"
1515
export { b as a, a as b } from "a"
1616
```
1717

1818
Examples of **correct** code for this rule:
1919

20-
```js
20+
```javascript
2121
export { a, b, c } from "a"
2222
export { b, C } from "a"
2323
export { a as b, b as a } from "a"

docs/rules/exports.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Sorts exports alphabetically and case insensitive in ascending order.
99

1010
Example of **incorrect** code for this rule:
1111

12-
```js
12+
```javascript
1313
export { c } from "./c"
1414
export default React
1515
export * from "./b"
@@ -19,7 +19,7 @@ export { a } from "./a"
1919

2020
Example of **correct** code for this rule:
2121

22-
```js
22+
```javascript
2323
export { a } from "./a"
2424
export * from "./b"
2525
export { c } from "./c"
@@ -77,7 +77,7 @@ groups as well as a custom regex sort group.
7777

7878
This configuration would result in the following output.
7979

80-
```js
80+
```javascript
8181
export { a }
8282
export { useState } from "react"
8383
export App from "~/components"

docs/rules/import-members.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Sorts import members alphabetically and case insensitive in ascending order.
99

1010
Examples of **incorrect** code for this rule:
1111

12-
```js
12+
```javascript
1313
import { b, c, a } from "a"
1414
import { C, b } from "a"
1515
import { b as a, a as b } from "a"
1616
```
1717

1818
Examples of **correct** code for this rule:
1919

20-
```js
20+
```javascript
2121
import { a, b, c } from "a"
2222
import { b, C } from "a"
2323
import { a as b, b as a } from "a"

docs/rules/imports.md

+46-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Sorts imports alphabetically and case insensitive in ascending order.
99

1010
Example of **incorrect** code for this rule:
1111

12-
```js
12+
```javascript
1313
import c from "c"
1414
import b from "b"
1515
import a from "a"
1616
```
1717

1818
Example of **correct** code for this rule:
1919

20-
```js
20+
```javascript
2121
import a from "a"
2222
import b from "b"
2323
import c from "c"
@@ -28,6 +28,7 @@ import c from "c"
2828
This rule has an object with its properties as:
2929

3030
- `"groups"` (default: `[]`)
31+
- `"separator"` (default: `""`)
3132

3233
### Groups
3334

@@ -69,7 +70,7 @@ groups as well as a custom regex sort group.
6970

7071
This configuration would result in the following output.
7172

72-
```js
73+
```javascript
7374
import "index.css"
7475
import React from "react"
7576
import { createStore } from "redux"
@@ -101,6 +102,48 @@ The configuration example above shows how this works where the static asset
101102
imports are the second sort group even though they have the highest order and
102103
are thus the last sort group in the resulting code.
103104

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+
104147
## When Not To Use It
105148

106149
This rule is a formatting preference and not following it won't negatively

docs/rules/object-properties.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Sorts object properties alphabetically and case insensitive in ascending order.
99

1010
Examples of **incorrect** code for this rule:
1111

12-
```js
12+
```javascript
1313
var a = { b: 1, c: 2, a: 3 }
1414
var a = { C: 1, b: 2 }
1515
var a = { C: 1, b: { y: 1, x: 2 } }
1616
```
1717

1818
Examples of **correct** code for this rule:
1919

20-
```js
20+
```javascript
2121
var a = { a: 1, b: 2, c: 3 }
2222
var a = { b: 1, C: 2 }
2323
var a = { b: { x: 1, y: 2 }, C: 1 }

jest.config.js

-19
This file was deleted.

package.json

+5-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"build": "tsup ./src/index.ts --format cjs,esm",
2121
"format": "prettier --write .",
2222
"lint": "eslint . --ext .ts",
23-
"test": "NODE_OPTIONS=--experimental-vm-modules pnpm jest",
23+
"test": "vitest",
2424
"ts": "tsc"
2525
},
2626
"type": "module",
@@ -41,27 +41,22 @@
4141
"natural-compare": "^1.4.0"
4242
},
4343
"devDependencies": {
44-
"@babel/cli": "^7.21.0",
4544
"@babel/core": "^7.21.0",
46-
"@babel/preset-env": "^7.20.2",
47-
"@babel/preset-typescript": "^7.21.0",
48-
"@jest/globals": "^29.5.0",
4945
"@mskelton/tsconfig": "^2.0.0",
46+
"@types/dedent": "^0.7.0",
5047
"@types/eslint": "^8.21.1",
5148
"@types/estree": "^1.0.0",
52-
"@types/jest": "^29.4.0",
5349
"@types/natural-compare": "^1.4.1",
5450
"@types/node": "^18.15.0",
5551
"@typescript-eslint/eslint-plugin": "^5.54.1",
5652
"@typescript-eslint/parser": "^5.54.1",
57-
"babel-jest": "^29.5.0",
53+
"dedent": "^0.7.0",
5854
"eslint": "^8.36.0",
5955
"eslint-config-prettier": "^8.7.0",
60-
"jest": "^29.5.0",
6156
"prettier": "^2.8.4",
6257
"semantic-release": "^20.1.1",
63-
"ts-jest": "^29.0.5",
6458
"tsup": "^6.6.3",
65-
"typescript": "^4.9.5"
59+
"typescript": "^4.9.5",
60+
"vitest": "^0.29.2"
6661
}
6762
}

0 commit comments

Comments
 (0)