Skip to content

Commit 25c00b6

Browse files
committed
feat: Migrating to @ianvs/prettier-plugin-sort-imports; update shared Prettier config
1 parent 09de351 commit 25c00b6

File tree

6 files changed

+129
-37
lines changed

6 files changed

+129
-37
lines changed

.prettierrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.prettierrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"printWidth": 90,
3+
"singleQuote": true,
4+
"plugins": [
5+
"@ianvs/prettier-plugin-sort-imports",
6+
"prettier-plugin-packagejson",
7+
"prettier-plugin-tailwindcss"
8+
],
9+
"importOrder": [
10+
"<TYPES>",
11+
"<TYPES>^[.]",
12+
"",
13+
"<BUILT_IN_MODULES>",
14+
"",
15+
"^react$",
16+
"<THIRD_PARTY_MODULES>",
17+
"",
18+
"^(src|~)(/.*)$",
19+
"",
20+
"^[.]"
21+
]
22+
}

README.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ This will install the shared config, as well as its peer dependencies:
3131
- [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier)
3232
- [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react)
3333
- [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
34-
- [eslint-plugin-simple-import-sort](https://github.com/lydell/eslint-plugin-simple-import-sort)
3534
- [eslint-plugin-sort-destructure-keys](https://github.com/mthadley/eslint-plugin-sort-destructure-keys)
3635
- [eslint-plugin-tailwindcss](https://github.com/francoismassart/eslint-plugin-tailwindcss)
3736
- [prettier](https://github.com/prettier/prettier)
37+
- [@ianvs/prettier-plugin-sort-imports](https://github.com/IanVS/prettier-plugin-sort-imports)
38+
- [prettier-plugin-packagejson](https://github.com/matzkoh/prettier-plugin-packagejson)
3839
- [prettier-plugin-tailwindcss](https://github.com/tailwindlabs/prettier-plugin-tailwindcss)
3940

4041
**NOTE:** if you are on NPM <7, you will need to install these manually:
@@ -114,6 +115,56 @@ This can also be overridden in your local `.eslintrc` file, if needed:
114115
}
115116
```
116117

118+
## Import Sorting
119+
120+
Import statement sorting is enabled via [`@ianvs/prettier-plugin-sort-imports`](https://github.com/IanVS/prettier-plugin-sort-imports), with the following default `importOrder` set:
121+
122+
```json
123+
{
124+
"importOrder": [
125+
"<TYPES>",
126+
"<TYPES>^[.]",
127+
"",
128+
"<BUILT_IN_MODULES>",
129+
"",
130+
"^react$",
131+
"<THIRD_PARTY_MODULES>",
132+
"",
133+
"^(src|~)(/.*)$",
134+
"",
135+
"^[.]"
136+
]
137+
}
138+
```
139+
140+
This will take import statements like these:
141+
142+
```js
143+
import fs from 'node:fs';
144+
145+
import { module } from 'package-name';
146+
147+
import foo from 'src/foo';
148+
149+
import main from '../index';
150+
import { bar } from './bar';
151+
```
152+
153+
And turn them into this:
154+
155+
```js
156+
import fs from 'node:fs';
157+
158+
import { module } from 'package-name';
159+
160+
import foo from 'src/foo';
161+
162+
import main from '../index';
163+
import { bar } from './bar';
164+
```
165+
166+
See the plugin [docs](https://github.com/IanVS/prettier-plugin-sort-imports#importorder) for more information on how to customize this option.
167+
117168
## Prettier
118169

119170
This config supports Prettier integration out of the box. Rules that may conflict with ESLint are disabled via recommended configuration in [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier).
@@ -135,7 +186,45 @@ If you wish to override any [Prettier options](https://prettier.io/docs/en/optio
135186
}
136187
```
137188

138-
Make sure that these rules match the options specified in your `.prettierrc` file.
189+
Make sure that these rules match the options specified in your Prettier config file.
190+
191+
### Shared Config
192+
193+
This package provides a shared Prettier config for use alongside the ESLint one.
194+
195+
To enable, create a Prettier config file (`.prettierrc`, `.prettierrc.js`, etc.), and import the shared Prettier config.
196+
197+
**JSON:**
198+
199+
```json
200+
// .prettierrc
201+
"eslint-config-acme/prettier"
202+
```
203+
204+
**CommonJS:**
205+
206+
```jsx
207+
// .prettierrc.js
208+
/** @type {import("prettier").Config} */
209+
const acme = require('eslint-config-acme/prettier');
210+
211+
module.exports = acme;
212+
```
213+
214+
If you'd like to override any of the default options, you can use the spread operator (`...`) to extend the default config:
215+
216+
```jsx
217+
// .prettierrc.js
218+
/** @type {import("prettier").Config} */
219+
const acme = require('eslint-config-acme/prettier');
220+
221+
const config = {
222+
...acme,
223+
singleQuote: false,
224+
};
225+
226+
module.exports = config;
227+
```
139228

140229
## Adding Scripts
141230

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
jsx: true,
2323
},
2424
},
25-
plugins: ['import', 'simple-import-sort', 'sort-destructure-keys', 'tailwindcss'],
25+
plugins: ['import', 'sort-destructure-keys', 'tailwindcss'],
2626
rules: {
2727
...base,
2828
...react,

lib/base.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,6 @@ module.exports = {
99
'import/first': 'error',
1010
'import/newline-after-import': 'error',
1111
'import/no-duplicates': 'error',
12-
'simple-import-sort/imports': [
13-
'error',
14-
{
15-
groups: [
16-
// Node.js builtins
17-
[
18-
'^node:',
19-
'^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)',
20-
],
21-
// Packages. `react` related packages come first
22-
['^react', '^@?\\w'],
23-
// Side effect imports
24-
['^\\u0000'],
25-
// Internal packages
26-
['^(~|src|internals)(/.*|$)'],
27-
// Parent imports. Put `..` last
28-
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
29-
// Other relative imports. Put same-folder imports and `.` last
30-
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
31-
// Style imports
32-
['^.+\\.s?css$'],
33-
],
34-
},
35-
],
36-
'simple-import-sort/exports': 'error',
3712
'sort-destructure-keys/sort-destructure-keys': 'warn',
3813
'tailwindcss/classnames-order': 'off',
3914
'no-console': 'warn',

package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-config-acme",
3-
"version": "2.3.0",
3+
"version": "3.0.1",
44
"description": "ESLint + Prettier config for React",
55
"keywords": [
66
"eslint",
@@ -22,32 +22,42 @@
2222
"name": "Mykhaylo Ryechkin",
2323
"url": "https://github.com/mryechkin"
2424
},
25+
"exports": {
26+
".": "./index.js",
27+
"./prettier": "./.prettierrc.json"
28+
},
2529
"main": "index.js",
2630
"files": [
2731
"LICENSE",
2832
"CHANGELOG.md",
2933
"README.md",
34+
".prettierrc.json",
3035
"index.js",
3136
"lib"
3237
],
3338
"scripts": {
3439
"lint": "eslint --ignore-path .gitignore .",
3540
"lint:fix": "eslint --fix"
3641
},
42+
"devDependencies": {
43+
"prettier": "^3.0.3",
44+
"prettier-plugin-packagejson": "^2.4.6"
45+
},
3746
"peerDependencies": {
47+
"@ianvs/prettier-plugin-sort-imports": "^4.1",
3848
"eslint": "^8.46",
3949
"eslint-config-airbnb": "^19.0",
40-
"eslint-config-prettier": "^8.10",
50+
"eslint-config-prettier": "^9.0.0",
4151
"eslint-import-resolver-custom-alias": "^1.3.2",
42-
"eslint-plugin-import": "^2.26",
43-
"eslint-plugin-jsx-a11y": "^6.6",
52+
"eslint-plugin-import": "^2.28",
53+
"eslint-plugin-jsx-a11y": "^6.7",
4454
"eslint-plugin-prettier": "^5.0",
4555
"eslint-plugin-react": "^7.33",
4656
"eslint-plugin-react-hooks": "^4.6",
47-
"eslint-plugin-simple-import-sort": "^10.0",
4857
"eslint-plugin-sort-destructure-keys": "^1.5.0",
4958
"eslint-plugin-tailwindcss": "^3.13",
5059
"prettier": "^3",
60+
"prettier-plugin-packagejson": "^2.4",
5161
"prettier-plugin-tailwindcss": "^0.5"
5262
},
5363
"engines": {

0 commit comments

Comments
 (0)