-
-
Notifications
You must be signed in to change notification settings - Fork 461
/
stylistic.ts
69 lines (60 loc) · 1.4 KB
/
stylistic.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { interopDefault } from '../utils'
import type { OptionsOverrides, StylisticConfig, TypedFlatConfigItem } from '../types'
import { pluginAntfu } from '../plugins'
export const StylisticConfigDefaults: StylisticConfig = {
indent: 2,
jsx: true,
quotes: 'single',
semi: false,
}
export interface StylisticOptions extends StylisticConfig, OptionsOverrides {
lessOpinionated?: boolean
}
export async function stylistic(
options: StylisticOptions = {},
): Promise<TypedFlatConfigItem[]> {
const {
indent,
jsx,
lessOpinionated = false,
overrides = {},
quotes,
semi,
} = {
...StylisticConfigDefaults,
...options,
}
const pluginStylistic = await interopDefault(import('@stylistic/eslint-plugin'))
const config = pluginStylistic.configs.customize({
flat: true,
indent,
jsx,
pluginName: 'style',
quotes,
semi,
})
return [
{
name: 'antfu/stylistic/rules',
plugins: {
antfu: pluginAntfu,
style: pluginStylistic,
},
rules: {
...config.rules,
'antfu/consistent-list-newline': 'error',
...(lessOpinionated
? {
curly: ['error', 'all'],
}
: {
'antfu/curly': 'error',
'antfu/if-newline': 'error',
'antfu/top-level-function': 'error',
}
),
...overrides,
},
},
]
}