Skip to content

Commit e5326ee

Browse files
Merge branch 'v6' into pr354
2 parents d9cae1b + e4a1b27 commit e5326ee

16 files changed

+646
-500
lines changed

CHANGELOG.md

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,83 @@
11
## Changelog
22

3-
---
43

4+
---
55
### 5.2.2
6-
76
- Update packages and pin babel/types [#343](https://github.com/trivago/prettier-plugin-sort-imports/pull/343) by [@byara](https://github.com/byara)
87

98
### 5.2.1
10-
119
- add svelte 5.x as peer dependency [#337](https://github.com/trivago/prettier-plugin-sort-imports/pull/337) by [@werner-drklein](https://github.com/werner-drklein)
1210

1311
### 5.2.0
14-
15-
- fix type import ordering [#331](https://github.com/trivago/prettier-plugin-sort-imports/pull/331) by [@rsslldnphy](https://github.com/rsslldnphy)
12+
- fix type import ordering [#331](https://github.com/trivago/prettier-plugin-sort-imports/pull/331) by [@rsslldnphy](https://github.com/rsslldnphy)
1613
- Fix conditional import of prettier-plugin-svelte [#332](https://github.com/trivago/prettier-plugin-sort-imports/pull/332) by [@rsslldnphy](https://github.com/rsslldnphy)
1714

1815
### v5.1.0
19-
2016
- Fix svelte packages being required all the time [#327](https://github.com/trivago/prettier-plugin-sort-imports/pull/327) by [@byara](https://github.com/byara)
2117

2218
### v5.0.1
23-
2419
- Clean up unwanted packages and unpin dependencies [#322](https://github.com/trivago/prettier-plugin-sort-imports/pull/322) by [@byara](https://github.com/byara)
2520

2621
### v5.0.0
27-
2822
#### New features
29-
3023
- Type imports [#153](https://github.com/trivago/prettier-plugin-sort-imports/pull/153) by [Xenfo](https://github.com/broofa)
3124
- Svelte support [#310](https://github.com/trivago/prettier-plugin-sort-imports/pull/310) by [canarddemagret](https://github.com/canarddemagret)
3225
- Side effect import support [#320](https://github.com/trivago/prettier-plugin-sort-imports/pull/320) by [blutorange](https://github.com/blutorange) and [vladislavarsenev](https://github.com/vladislavarsenev)
3326
- Fixed dollar sign group replace in Vue [#283](https://github.com/trivago/prettier-plugin-sort-imports/pull/283) by [adamDilger](https://github.com/adamDilger)
3427
- Support `importOrderImportAttributesKeyword` [#273](https://github.com/trivago/prettier-plugin-sort-imports/pull/273) by [chentsulin](https://github.com/chentsulin)
3528

36-
### v4.3.0
3729

30+
### v4.3.0
3831
#### New features
39-
4032
- added support for sort-imports-ignore [#237](https://github.com/trivago/prettier-plugin-sort-imports/pull/237) by [stephdotnet](https://github.com/stephdotnet)
4133
- Upgrade node in CI to current and lts versions [#264](https://github.com/trivago/prettier-plugin-sort-imports/pull/264) by [harryzcy](https://github.com/harryzcy)
4234

4335
### v4.2.1
44-
4536
#### Chore
46-
4737
- Resolves Issue 262 - CVE-2023-45133 - upgrade to latest babel traverse [#266](https://github.com/trivago/prettier-plugin-sort-imports/pull/266) by [c-h-russell-walker](https://github.com/c-h-russell-walker)
4838

4939
### v4.2.0
50-
5140
#### Chore
52-
5341
- update prettier peer dependency semVer to include 3.x [#239](https://github.com/trivago/prettier-plugin-sort-imports/pull/239) by [basselworkforce](https://github.com/basselworkforce)
5442

5543
### v4.1.1
56-
5744
#### Revert
58-
5945
- Type imports[#153](https://github.com/trivago/prettier-plugin-sort-imports/pull/153) by [Xenfo](https://github.com/broofa)
6046

6147
### v4.1.0
62-
6348
#### New features
64-
65-
- Move @babel/core to devDependencies [#200](https://github.com/trivago/prettier-plugin-sort-imports/pull/200) by [yykamei](https://github.com/yykamei)
66-
- Only preserve directives already at the start of the program [#198](https://github.com/trivago/prettier-plugin-sort-imports/pull/198) by [c-dante](https://github.com/c-dante)
49+
- Move @babel/core to devDependencies [#200](https://github.com/trivago/prettier-plugin-sort-imports/pull/200) by [yykamei](https://github.com/yykamei)
50+
- Only preserve directives already at the start of the program [#198](https://github.com/trivago/prettier-plugin-sort-imports/pull/198) by [c-dante](https://github.com/c-dante)
6751
- Bump babel to support satisfies keyword [#196](https://github.com/trivago/prettier-plugin-sort-imports/pull/196) by [Leomotors](https://github.com/Leomotors)
68-
- Update prettier for TS 4.9 [#194](https://github.com/trivago/prettier-plugin-sort-imports/pull/194) by [taiwabisabi](https://github.com/taiwabisabi)
52+
- Update prettier for TS 4.9 [#194](https://github.com/trivago/prettier-plugin-sort-imports/pull/194) by [taiwabisabi](https://github.com/taiwabisabi)
6953
- Fixed empty/no script tag in vue component error [#192](https://github.com/trivago/prettier-plugin-sort-imports/pull/192) by [adamDilger](https://github.com/adamDilger)
7054
- Change @vue/compiler-sfc to an optional dependency[#189](https://github.com/trivago/prettier-plugin-sort-imports/pull/189) by [transitive-bullshit](https://github.com/transitive-bullshit)
7155
- Type imports[#153](https://github.com/trivago/prettier-plugin-sort-imports/pull/153) by [Xenfo](https://github.com/broofa)
7256

7357
### v4.0.0
74-
7558
#### New features
76-
7759
- Make @vue/compiler-sfc peer dependency [#183](https://github.com/trivago/prettier-plugin-sort-imports/pull/183) by [blake-newman](https://github.com/blake-newman)
7860
- Keep script directives at top of file [#186](https://github.com/trivago/prettier-plugin-sort-imports/pull/186) by [broofa](https://github.com/broofa)
7961

8062
### v3.4.0
81-
8263
#### New features
83-
8464
- Vue JS support [#174](https://github.com/trivago/prettier-plugin-sort-imports/pull/174) by [blake-newman](https://github.com/blake-newman)
8565
- Export config type [#173](https://github.com/trivago/prettier-plugin-sort-imports/pull/173) by [Leomotors](https://github.com/Leomotors)
8666

8767
### v3.3.1
88-
8968
#### Chores
90-
9169
- Update @babel/parser (to support TypeScript 4.7) [#161](https://github.com/trivago/prettier-plugin-sort-imports/pull/161) by [odiak](https://github.com/odiak)
9270

9371
### v3.3.0
94-
9572
#### Chores
96-
9773
- Update babel version [#134](https://github.com/trivago/prettier-plugin-sort-imports/pull/147) by [marvinroger](https://github.com/marvinroger)
9874
- Fix typo in Migration docs [#158](https://github.com/trivago/prettier-plugin-sort-imports/pull/158) by [raineorshine](https://github.com/raineorshine)
9975

10076
### v3.2.0
101-
10277
#### New features
103-
10478
- Group Namespace specifiers [#105](https://github.com/trivago/prettier-plugin-sort-imports/pull/105) by [Mattinton](https://github.com/Mattinton)
10579

10680
#### Chores
107-
10881
- Clean up unit test and snapshot test
10982
- Add contribution guidelines for bug fixes and new features
11083

@@ -115,21 +88,19 @@
11588
### v3.1.0
11689

11790
#### Chores
118-
11991
- Update Babel parser to `7.14.6` [#79](https://github.com/trivago/prettier-plugin-sort-imports/pull/79) by [juanrgm](https://github.com/juanrgm)
12092
- `.npmignore` cleanup [#96](https://github.com/trivago/prettier-plugin-sort-imports/issues/96) by [byara](https://github.com/byara)
121-
- Remove npm badges in the README [#101](https://github.com/trivago/prettier-plugin-sort-imports/issues/101) by [byara](https://github.com/byara)
93+
- Remove npm badges in the README [#101](https://github.com/trivago/prettier-plugin-sort-imports/issues/101) by [byara](https://github.com/byara)
12294

12395
### v3.0.0
12496

12597
#### New features
126-
12798
- `<THIRD_PARTY_MODULES>` special word in import order to place third
128-
party imports at desired place. [#65](https://github.com/trivago/prettier-plugin-sort-imports/pull/65) by [@risenforces](https://github.com/risenforces)
99+
party imports at desired place. [#65](https://github.com/trivago/prettier-plugin-sort-imports/pull/65) by [@risenforces](https://github.com/risenforces)
129100
- `importOrderSortSpecifiers` option to sort the imports in an import declaration. [#72](https://github.com/trivago/prettier-plugin-sort-imports/pull/72) by [@ratierd](https://github.com/ratierd)
130-
- `importOrderCaseInsensitive` option to control the case sensitivity [#69](https://github.com/trivago/prettier-plugin-sort-imports/pull/79) by [@timiles](https://github.com/timiles)
131-
- `importOrderParserPlugins` option to pass plugins to babel parser [#88](https://github.com/trivago/prettier-plugin-sort-imports/pull/88) by [@saaryab](https://github.com/saaryab)
101+
- `importOrderCaseInsensitive` option to control the case sensitivity [#69](https://github.com/trivago/prettier-plugin-sort-imports/pull/79) by [@timiles](https://github.com/timiles)
102+
- `importOrderParserPlugins` option to pass plugins to babel parser [#88](https://github.com/trivago/prettier-plugin-sort-imports/pull/88) by [@saaryab](https://github.com/saaryab)
132103

133104
#### Breaking Changes
134-
135105
- Renaming of the `experimentalBabelParserPluginsList` to `importOrderParserPlugins`. by [@byara](https://github.com/byara)
106+

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Subsequent pull requests only need to follow step 3 and beyond.
3232

3333
**NOTE**: While there are other ways to accomplish the steps using other tools,
3434
the examples here will assume most actions will be performed via `git` on
35-
command line.
35+
command line.

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Popup } from '@ui/Popup';
2525
import { createConnection } from '@server/database';
2626
```
2727

28+
2829
### Output
2930

3031
```javascript
@@ -91,7 +92,7 @@ module.exports = {
9192
}
9293
```
9394

94-
**Note:** There may be an issue with some package managers, such as `pnpm` or when using `prettier` v3.x. You can solve it by providing additional configuration option in prettier config file.
95+
**Note: There may be an issue with some package managers, such as `pnpm` or when using `prettier` v3.x. You can solve it by providing additional configuration option in prettier config file.
9596

9697
```js
9798
module.exports = {
@@ -206,10 +207,15 @@ with options as a JSON string of the plugin array:
206207
importOrderParserPlugins: []
207208
```
208209

209-
#### `importOrderSideEffects`
210+
### `importOrderSortByLength`
211+
**type**: `'asc' | 'desc' | null`
212+
**default value**: `null`
210213

211-
**type**: `boolean`
214+
A choice value to enable sorting imports within their groups based on their string lengths, the two options being ascending and descending.
215+
Leaving the value blank or setting it to null will result in length being ignored
212216

217+
### `importOrderSideEffects`
218+
**type**: `boolean`
213219
**default value**: `true`
214220

215221
By default, the plugin sorts [side effect imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_a_module_for_its_side_effects_only) like any other imports in the file. If you need to keep side effect imports in the same place but sort all other imports around them, set this option to false.
@@ -227,7 +233,6 @@ import 'side-effect-lib'
227233
import c from 'c'
228234
import b from 'b'
229235
```
230-
231236
When sorted:
232237

233238
```js
@@ -242,12 +247,20 @@ import c from 'c'
242247

243248
### Ignoring import ordering
244249

250+
In some cases it's desired to ignore import ordering, specifically if you require to instantiate a common service or polyfill in your application logic before all the other imports. The plugin supports the `// sort-imports-ignore` comment, which will exclude the file from ordering the imports.
251+
252+
```javascript
253+
// sort-imports-ignore
254+
import './polyfills';
255+
256+
import foo from 'foo'
257+
```
258+
245259
#### `importOrderImportAttributesKeyword`
246260

247261
**type**: `'assert' | 'with' | 'with-legacy'`
248262

249-
The import attributes/assertions syntax:
250-
263+
The import attributes/assertions syntax:
251264
- `with`: `import "..." with { type: "json" }`
252265
- `assert`: `import "..." assert { type: "json" }`
253266
- `with-legacy`: `import "..." with type: "json"`.
@@ -258,6 +271,7 @@ The import attributes/assertions syntax:
258271

259272
_Default behavior:_ When not specified, @babel/generator will try to match the style in the input code based on the AST shape.
260273

274+
261275
### How does import sort work ?
262276

263277
The plugin extracts the imports which are defined in `importOrder`. These imports are considered as _local imports_.
@@ -292,9 +306,9 @@ Having some trouble or an issue ? You can check [FAQ / Troubleshooting section](
292306
Want to highlight your project or company ? Adding your project / company name will help plugin to gain attraction and contribution.
293307
Feel free to make a Pull Request to add your project / company name.
294308

295-
- [trivago](https://company.trivago.com)
296-
- [AuresKonnect](https://aures.com)
297-
- [FactorialHR](https://factorialhr.com)
309+
- [trivago](https://company.trivago.com)
310+
- [AuresKonnect](https://aures.com)
311+
- [FactorialHR](https://factorialhr.com)
298312

299313
### Contribution
300314

src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ const options: Options = {
5656
default: false,
5757
description: 'Should specifiers be sorted?',
5858
},
59+
importOrderSortByLength: {
60+
type: 'choice',
61+
category: 'Global',
62+
default: null,
63+
choices: [
64+
{ value: 'asc', description: 'will sort from shortest to longest' },
65+
{
66+
value: 'desc',
67+
description: 'will sort from longest to shortest',
68+
},
69+
{
70+
value: null,
71+
description: 'will disable sorting based on length',
72+
},
73+
],
74+
description: 'Should imports be sorted by their string length',
75+
},
5976
importOrderSideEffects: {
6077
type: 'boolean',
6178
category: 'Global',

src/preprocessors/preprocessor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function preprocessor(code: string, options: PrettierOptions) {
1616
importOrderSeparation,
1717
importOrderGroupNamespaceSpecifiers,
1818
importOrderSortSpecifiers,
19+
importOrderSortByLength,
1920
importOrderSideEffects,
2021
importOrderImportAttributesKeyword,
2122
} = options;
@@ -44,6 +45,7 @@ export function preprocessor(code: string, options: PrettierOptions) {
4445
importOrderSeparation,
4546
importOrderGroupNamespaceSpecifiers,
4647
importOrderSortSpecifiers,
48+
importOrderSortByLength,
4749
importOrderSideEffects,
4850
});
4951

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type GetSortedNodes = (
1919
| 'importOrderSeparation'
2020
| 'importOrderGroupNamespaceSpecifiers'
2121
| 'importOrderSortSpecifiers'
22+
| 'importOrderSortByLength'
2223
| 'importOrderSideEffects'
2324
>,
2425
) => ImportOrLine[];

src/utils/__tests__/get-all-comments-from-nodes.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const getSortedImportNodes = (code: string, options?: ParserOptions) => {
1515
importOrderSeparation: false,
1616
importOrderGroupNamespaceSpecifiers: false,
1717
importOrderSortSpecifiers: false,
18+
importOrderSortByLength: null,
1819
importOrderSideEffects: true,
1920
});
2021
};

src/utils/__tests__/get-code-from-ast.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import a from 'a';
2525
importOrderSeparation: false,
2626
importOrderGroupNamespaceSpecifiers: false,
2727
importOrderSortSpecifiers: false,
28+
importOrderSortByLength: null,
2829
importOrderSideEffects: true,
2930
});
3031
const formatted = getCodeFromAst(sortedNodes, [], code, null);

src/utils/__tests__/get-import-nodes-matched-group.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from 'vitest';
22

3-
import { THIRD_PARTY_MODULES_SPECIAL_WORD } from '../../constants.js';
4-
import { ImportGroups } from '../../types';
53
import { getImportNodesMatchedGroup } from '../get-import-nodes-matched-group.js';
64
import { getImportNodes } from '../get-import-nodes.js';
75

0 commit comments

Comments
 (0)