Skip to content

Commit f9b249b

Browse files
jthecrypticace
andauthored
Ianvs prettier plugin sort imports (#122)
* Add "@ianvs/prettier-plugin-sort-imports" to list of compatible plugins * add "@ianvs/prettier-plugin-sort-imports" to readme * Update dependencies * Add test * Update test * Fix existing changelog entry * Update changelog --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
1 parent e14a94b commit f9b249b

File tree

6 files changed

+110
-1
lines changed

6 files changed

+110
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12-
- Don't sort classes in Glimmer `concat` helper.
12+
- Don't sort classes in Glimmer `concat` helper ([#119](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/119))
13+
- Add support for `@ianvs/prettier-plugin-sort-imports` ([#122](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/122))
1314

1415
## [0.2.2] - 2023-01-24
1516

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This plugin uses Prettier APIs that can only be used by one plugin at a time, ma
4545
- `@prettier/plugin-php`
4646
- `@prettier/plugin-pug`
4747
- `@shopify/prettier-plugin-liquid`
48+
- `@ianvs/prettier-plugin-sort-imports`
4849
- `@trivago/prettier-plugin-sort-imports`
4950
- `prettier-plugin-astro`
5051
- `prettier-plugin-css-order`

package-lock.json

+70
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"format": "prettier \"src/**/*.js\" \"scripts/**/*.js\" \"tests/test.js\" --write --print-width 100 --single-quote --no-semi --plugin-search-dir ./tests"
2727
},
2828
"devDependencies": {
29+
"@ianvs/prettier-plugin-sort-imports": "^3.7.0",
2930
"@prettier/plugin-php": "^0.19.2",
3031
"@prettier/plugin-pug": "^2.3.0",
3132
"@shopify/prettier-plugin-liquid": "^1.0.3",
@@ -59,6 +60,7 @@
5960
"tailwindcss": "^3.0.23"
6061
},
6162
"peerDependencies": {
63+
"@ianvs/prettier-plugin-sort-imports": "*",
6264
"@prettier/plugin-php": "*",
6365
"@prettier/plugin-pug": "*",
6466
"@shopify/prettier-plugin-liquid": "*",
@@ -76,6 +78,9 @@
7678
"prettier-plugin-twig-melody": "*"
7779
},
7880
"peerDependenciesMeta": {
81+
"@ianvs/prettier-plugin-sort-imports": {
82+
"optional": true
83+
},
7984
"@prettier/plugin-php": {
8085
"optional": true
8186
},

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ function getCompatibleParser(parserFormat, options) {
857857

858858
// Now load parsers from plugins
859859
let compatiblePlugins = [
860+
'@ianvs/prettier-plugin-sort-imports',
860861
'@trivago/prettier-plugin-sort-imports',
861862
'prettier-plugin-organize-imports',
862863
'@prettier/plugin-php',

tests/plugins.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@ let tests = [
5050
],
5151
}
5252
},
53+
{
54+
plugins: [
55+
'@ianvs/prettier-plugin-sort-imports',
56+
],
57+
options: {
58+
importOrder: ["^@tailwindcss/(.*)$", "^@babel/(.*)$", "^[./]"],
59+
importOrderSortSpecifiers: true,
60+
},
61+
tests: {
62+
babel: [
63+
[
64+
`import './i-haz-side-effects'\nimport i3 from './three'\nimport i2 from '@two/file'\nimport i1 from '@one/file'`,
65+
`import './i-haz-side-effects'\nimport i1 from '@one/file'\nimport i2 from '@two/file'\nimport i3 from './three'`,
66+
],
67+
],
68+
typescript: [
69+
[
70+
`import './i-haz-side-effects'\nimport i3 from './three'\nimport i2 from '@two/file'\nimport i1 from '@one/file'`,
71+
`import './i-haz-side-effects'\nimport i1 from '@one/file'\nimport i2 from '@two/file'\nimport i3 from './three'`,
72+
],
73+
],
74+
75+
// This plugin does not support babel-ts
76+
'babel-ts': [
77+
[
78+
`import './three'\nimport '@two/file'\nimport '@one/file'`,
79+
`import './three'\nimport '@two/file'\nimport '@one/file'`,
80+
],
81+
],
82+
}
83+
},
5384
{
5485
plugins: [
5586
'prettier-plugin-organize-imports',

0 commit comments

Comments
 (0)