Skip to content

Commit 47507d1

Browse files
committed
refactor!: migrate from prettier to eslint-stylistic
1 parent 4ab51a6 commit 47507d1

32 files changed

+899
-361
lines changed

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
"gql",
2020
"graphql"
2121
],
22+
// "eslint.runtime": "node",
23+
"eslint.rules.customizations": [
24+
{ "rule": "style/*", "severity": "off" },
25+
{ "rule": "*-indent", "severity": "off" },
26+
{ "rule": "*-spacing", "severity": "off" },
27+
{ "rule": "*-spaces", "severity": "off" },
28+
{ "rule": "*-order", "severity": "off" },
29+
{ "rule": "*-dangle", "severity": "off" },
30+
{ "rule": "*-newline", "severity": "off" },
31+
{ "rule": "*quotes", "severity": "off" },
32+
{ "rule": "*semi", "severity": "off" }
33+
],
2234
"prettier.enable": false,
2335
"cSpell.words": ["antfu", "coderwyd", "rspack", "unocss"]
2436
}

README.md

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- ✨ Support Vue, React, Svelte.
1111
- 🎯 Designed to work with TypeScript, Vue out-of-box
1212
- 🏆 Reasonable defaults, best practices, only one-line of config
13-
- 🎨 Use ESlint and Prettier to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown, JSON, JSONC.
13+
- 🎨 Use ESlint to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown, JSON, JSONC.
1414

1515
## Usage
1616

@@ -72,6 +72,20 @@ Add the following settings to your `.vscode/settings.json`:
7272
"source.organizeImports": "never"
7373
},
7474

75+
// Silent the stylistic rules in you IDE, but still auto fix them
76+
"eslint.rules.customizations": [
77+
{ "rule": "style/*", "severity": "off" },
78+
{ "rule": "format/*", "severity": "off" },
79+
{ "rule": "*-indent", "severity": "off" },
80+
{ "rule": "*-spacing", "severity": "off" },
81+
{ "rule": "*-spaces", "severity": "off" },
82+
{ "rule": "*-order", "severity": "off" },
83+
{ "rule": "*-dangle", "severity": "off" },
84+
{ "rule": "*-newline", "severity": "off" },
85+
{ "rule": "*quotes", "severity": "off" },
86+
{ "rule": "*semi", "severity": "off" }
87+
],
88+
7589
// Enable eslint for all supported languages
7690
"eslint.validate": [
7791
"html",
@@ -113,8 +127,8 @@ npm i -D lint-staged simple-git-hooks
113127

114128
### interface Options
115129

116-
````ts
117-
interface OptionsConfig {
130+
```ts
131+
interface OptionsConfig extends OptionsComponentExts {
118132
/**
119133
* The current working directory
120134
*
@@ -146,6 +160,15 @@ interface OptionsConfig {
146160
*/
147161
typescript?: boolean | OptionsTypescript
148162

163+
/**
164+
* Enable JSX related rules.
165+
*
166+
* Currently only stylistic rules are included.
167+
*
168+
* @default true
169+
*/
170+
jsx?: boolean
171+
149172
/**
150173
* Enable test support.
151174
*
@@ -171,7 +194,7 @@ interface OptionsConfig {
171194
* Enable react rules.
172195
*
173196
* Requires installing:
174-
* - `eslint-plugin-react`
197+
* - `@eslint-react/eslint-plugin`
175198
* - `eslint-plugin-react-hooks`
176199
* - `eslint-plugin-react-refresh`
177200
*
@@ -207,13 +230,20 @@ interface OptionsConfig {
207230
unocss?: boolean | OptionsUnoCSS
208231

209232
/**
210-
* Whether to use prettierrc
233+
* Enable stylistic rules.
211234
*
212-
* If true, the rules in prettierrc will override the default rules
235+
* @see https://eslint.style/
236+
* @default true
237+
*/
238+
stylistic?: boolean | (StylisticConfig & OptionsOverrides)
239+
240+
/**
241+
* Enable regexp rules.
213242
*
243+
* @see https://ota-meshi.github.io/eslint-plugin-regexp/
214244
* @default true
215245
*/
216-
usePrettierrc?: boolean
246+
regexp?: boolean | (OptionsRegExp & OptionsOverrides)
217247

218248
/**
219249
* Use external formatters to format files.
@@ -227,32 +257,25 @@ interface OptionsConfig {
227257
* "yaml": false
228258
* "toml": false
229259
* }
230-
*/
231-
formatter?: OptionsFormatters
232-
233-
/**
234-
* Default prettier rules
235260
*
236-
* @default
237-
* ```json
238-
* {
239-
* "arrowParens": "avoid",
240-
* "htmlWhitespaceSensitivity": "ignore"
241-
* "printWidth": 80,
242-
* "semi": false,
243-
* "singleQuote": true,
244-
* }
245-
* ```
261+
* When set to `true`, it will enable all formatters.
246262
*/
247-
prettierRules?: PartialPrettierExtendedOptions
263+
formatter?: boolean | OptionsFormatters
248264

249265
/**
250266
* Control to disable some rules in editors.
251267
* @default auto-detect based on the process.env
252268
*/
253269
isInEditor?: boolean
270+
271+
/**
272+
* Automatically rename plugins in the config.
273+
*
274+
* @default true
275+
*/
276+
autoRenamePlugins?: boolean
254277
}
255-
````
278+
```
256279

257280
## Thanks
258281

eslint.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import styleMigrate from '@stylistic/eslint-plugin-migrate'
12
import JITI from 'jiti'
23

34
const jiti = JITI(import.meta.url)
45
/**
56
* @type {import('./src').defineConfig}
67
*/
78
const { defineConfig } = jiti('./src')
8-
99
export default defineConfig(
1010
{
1111
vue: true,
@@ -19,4 +19,13 @@ export default defineConfig(
1919
'perfectionist/sort-objects': 'error',
2020
},
2121
},
22+
{
23+
files: ['src/configs/*.ts'],
24+
plugins: {
25+
'style-migrate': styleMigrate,
26+
},
27+
rules: {
28+
'style-migrate/migrate': ['error', { namespaceTo: 'style' }],
29+
},
30+
},
2231
)

example/js.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function test() {}
22
test()
3-
;[1, 2, 3, 4, 5].forEach(item => {
3+
;[1, 2, 3, 4, 5].forEach((item) => {
44
console.error(item, 'item')
55
})

example/ts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ function test(): string {
55
}
66

77
test()
8-
;[1, 2, 3, 4, 5].forEach(item => {
8+
;[1, 2, 3, 4, 5].forEach((item) => {
99
console.warn(item, 'item')
1010
})

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"eslint-config",
1313
"eslint-config-vue",
1414
"eslint-config-react",
15-
"eslint-config-svelte",
16-
"prettier"
15+
"eslint-config-svelte"
1716
],
1817
"publishConfig": {
1918
"access": "public"
@@ -52,6 +51,7 @@
5251
"@eslint-react/eslint-plugin": "^1.5.8",
5352
"@unocss/eslint-plugin": ">=0.50.0",
5453
"eslint": "^8.56.0 || ^9.0.0",
54+
"eslint-plugin-format": ">=0.1.0",
5555
"eslint-plugin-react-hooks": "^4.6.0",
5656
"eslint-plugin-react-refresh": "^0.4.4",
5757
"eslint-plugin-svelte": "^2.34.1",
@@ -64,6 +64,9 @@
6464
"@unocss/eslint-plugin": {
6565
"optional": true
6666
},
67+
"eslint-plugin-format": {
68+
"optional": true
69+
},
6770
"eslint-plugin-react-hooks": {
6871
"optional": true
6972
},
@@ -79,11 +82,12 @@
7982
},
8083
"dependencies": {
8184
"@antfu/install-pkg": "^0.3.3",
85+
"@stylistic/eslint-plugin": "^2.1.0",
8286
"@toml-tools/parser": "^1.0.0",
8387
"@typescript-eslint/eslint-plugin": "^7.9.0",
8488
"@typescript-eslint/parser": "^7.9.0",
8589
"eslint-config-flat-gitignore": "^0.1.5",
86-
"eslint-config-prettier": "^9.1.0",
90+
"eslint-merge-processors": "^0.1.0",
8791
"eslint-plugin-antfu": "^2.2.0",
8892
"eslint-plugin-command": "^0.2.3",
8993
"eslint-plugin-eslint-comments": "^3.2.0",
@@ -93,20 +97,19 @@
9397
"eslint-plugin-n": "^17.7.0",
9498
"eslint-plugin-no-only-tests": "^3.1.0",
9599
"eslint-plugin-perfectionist": "^2.10.0",
96-
"eslint-plugin-prettier": "^5.1.3",
97100
"eslint-plugin-regexp": "^2.5.0",
98101
"eslint-plugin-tailwindcss": "^3.15.2",
99102
"eslint-plugin-unicorn": "^53.0.0",
100103
"eslint-plugin-unused-imports": "^3.2.0",
101104
"eslint-plugin-vitest": "^0.5.4",
102105
"eslint-plugin-vue": "^9.26.0",
106+
"eslint-processor-vue-blocks": "^0.1.2",
103107
"eslint-typegen": "^0.2.4",
104108
"globals": "^15.3.0",
105109
"jsonc-eslint-parser": "^2.4.0",
106110
"local-pkg": "^0.5.0",
107111
"parse-gitignore": "^2.0.0",
108112
"picocolors": "^1.0.1",
109-
"prettier": "^3.2.5",
110113
"prettier-plugin-toml": "^2.0.1",
111114
"prompts": "^2.4.2",
112115
"vue-eslint-parser": "^9.4.2",
@@ -116,6 +119,7 @@
116119
"@antfu/ni": "^0.21.12",
117120
"@eslint-react/eslint-plugin": "^1.5.12",
118121
"@eslint/config-inspector": "^0.4.8",
122+
"@stylistic/eslint-plugin-migrate": "^2.1.0",
119123
"@types/eslint": "^8.56.10",
120124
"@types/fs-extra": "^11.0.4",
121125
"@types/node": "^20.12.12",
@@ -124,6 +128,7 @@
124128
"@unocss/eslint-plugin": "^0.60.2",
125129
"bumpp": "^9.4.1",
126130
"eslint": "^9.3.0",
131+
"eslint-plugin-format": "^0.1.1",
127132
"eslint-plugin-react": "^7.34.1",
128133
"eslint-plugin-react-hooks": "^4.6.2",
129134
"eslint-plugin-react-refresh": "^0.4.7",

0 commit comments

Comments
 (0)