Skip to content

Commit 4a7200d

Browse files
committed
feat!: use unified stylistic rules
1 parent d1f1779 commit 4a7200d

File tree

4 files changed

+37
-101
lines changed

4 files changed

+37
-101
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@
4141
"eslint": ">=8.0.0"
4242
},
4343
"dependencies": {
44-
"@eslint-stylistic/metadata": "0.0.4",
45-
"@stylistic/eslint-plugin-js": "0.0.4",
46-
"@stylistic/eslint-plugin-ts": "0.0.4",
44+
"@stylistic/eslint-plugin": "^0.0.5",
4745
"@typescript-eslint/eslint-plugin": "^6.7.2",
4846
"@typescript-eslint/parser": "^6.7.2",
4947
"astro-eslint-parser": "^0.15.0",
@@ -71,7 +69,6 @@
7169
"yaml-eslint-parser": "^1.2.2"
7270
},
7371
"devDependencies": {
74-
"@stylistic/eslint-plugin-migrate": "0.0.4",
7572
"@types/node": "^20.6.3",
7673
"@types/react": "^18.2.22",
7774
"bumpp": "^9.2.0",

pnpm-lock.yaml

Lines changed: 28 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/stylistic.ts

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
import type { FlatESLintConfigItem } from 'eslint-define-config'
2-
import { packages } from '@eslint-stylistic/metadata'
3-
import { pluginStylisticJs, pluginStylisticTs, pluginTs } from '../plugins'
4-
import { OFF } from '../flags'
5-
6-
const tsPackage = packages.find(i => i.shortId === 'ts')!
2+
import { pluginStylistic } from '../plugins'
73

84
export const javascriptStylistic: FlatESLintConfigItem[] = [
95
{
106
plugins: {
11-
style: pluginStylisticJs,
7+
style: pluginStylistic,
128
},
139
rules: {
1410
'antfu/consistent-list-newline': 'error',
1511
'antfu/if-newline': 'error',
1612

17-
'comma-dangle': ['error', 'always-multiline'],
1813
'curly': ['error', 'multi-or-nest', 'consistent'],
19-
'quotes': ['error', 'single'],
20-
'semi': ['error', 'never'],
2114

2215
'style/array-bracket-spacing': ['error', 'never'],
2316
'style/arrow-spacing': ['error', { after: true, before: true }],
2417
'style/block-spacing': ['error', 'always'],
2518
'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
19+
'style/comma-dangle': ['error', 'always-multiline'],
2620
'style/comma-spacing': ['error', { after: true, before: false }],
2721
'style/comma-style': ['error', 'last'],
2822
'style/computed-property-spacing': ['error', 'never', { enforceForClassMembers: true }],
@@ -68,6 +62,7 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
6862
'style/key-spacing': ['error', { afterColon: true, beforeColon: false }],
6963
'style/keyword-spacing': ['error', { after: true, before: true }],
7064
'style/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
65+
'style/member-delimiter-style': ['error', { multiline: { delimiter: 'none' } }],
7166
'style/multiline-ternary': ['error', 'always-multiline'],
7267
'style/no-mixed-spaces-and-tabs': 'error',
7368
'style/no-multi-spaces': 'error',
@@ -79,7 +74,9 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
7974
'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
8075
'style/operator-linebreak': ['error', 'before'],
8176
'style/padded-blocks': ['error', { blocks: 'never', classes: 'never', switches: 'never' }],
77+
'style/quotes': ['error', 'single'],
8278
'style/rest-spread-spacing': ['error', 'never'],
79+
'style/semi': ['error', 'never'],
8380
'style/semi-spacing': ['error', { after: true, before: false }],
8481
'style/space-before-blocks': ['error', 'always'],
8582
'style/space-before-function-paren': ['error', { anonymous: 'always', asyncArrow: 'always', named: 'never' }],
@@ -99,62 +96,8 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
9996
}],
10097
'style/template-curly-spacing': 'error',
10198
'style/template-tag-spacing': ['error', 'never'],
99+
'style/type-annotation-spacing': ['error', {}],
102100
'style/yield-star-spacing': ['error', 'both'],
103101
},
104102
},
105103
]
106-
107-
export const typescriptStylistic: FlatESLintConfigItem[] = [
108-
{
109-
plugins: {
110-
'style-ts': pluginStylisticTs,
111-
'ts': pluginTs as any,
112-
},
113-
rules: {
114-
...stylisticJsToTS(javascriptStylistic[0].rules!),
115-
116-
'comma-dangle': OFF,
117-
'quotes': OFF,
118-
'semi': OFF,
119-
120-
'style-ts/member-delimiter-style': ['error', { multiline: { delimiter: 'none' } }],
121-
'style-ts/type-annotation-spacing': ['error', {}],
122-
123-
'ts/comma-dangle': ['error', 'always-multiline'],
124-
'ts/quotes': ['error', 'single'],
125-
'ts/semi': ['error', 'never'],
126-
},
127-
},
128-
]
129-
130-
// TODO: move to ESLint Stylistic
131-
function stylisticJsToTS(input: Record<string, any>) {
132-
return {
133-
// turn off all stylistic rules from style
134-
...Object.fromEntries(
135-
Object.entries(input)
136-
.map(([key]) => {
137-
if (!key.startsWith('style/'))
138-
return null!
139-
const basename = key.replace('style/', '')
140-
if (tsPackage.rules.find(i => i.name === basename))
141-
return [key, OFF]
142-
return null!
143-
})
144-
.filter(Boolean),
145-
),
146-
// rename all stylistic rules from style to style/ts
147-
...Object.fromEntries(
148-
Object.entries(input)
149-
.map(([key, value]) => {
150-
if (!key.startsWith('style/'))
151-
return null!
152-
const basename = key.replace('style/', '')
153-
return tsPackage.rules.find(i => i.name === basename)
154-
? [`style-ts/${basename}`, value]
155-
: null!
156-
})
157-
.filter(Boolean),
158-
),
159-
}
160-
}

src/plugins.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export { default as pluginJsdoc } from 'eslint-plugin-jsdoc'
88
export { default as pluginJsonc } from 'eslint-plugin-jsonc'
99
export { default as pluginMarkdown } from 'eslint-plugin-markdown'
1010
export { default as pluginNode } from 'eslint-plugin-n'
11-
export { default as pluginStylisticJs } from '@stylistic/eslint-plugin-js'
12-
export { default as pluginStylisticTs } from '@stylistic/eslint-plugin-ts'
11+
export { default as pluginStylistic } from '@stylistic/eslint-plugin'
1312
export { default as pluginTs } from '@typescript-eslint/eslint-plugin'
1413
export { default as pluginUnicorn } from 'eslint-plugin-unicorn'
1514
export { default as pluginUnusedImports } from 'eslint-plugin-unused-imports'

0 commit comments

Comments
 (0)