-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsx.ts
65 lines (60 loc) · 1.44 KB
/
jsx.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
import { GLOB_JSX_MJSX, GLOB_TSX_MTSX } from '../globs'
import { PARSER_TS } from '../parsers'
import { PLUGIN_REACT, PLUGIN_SORT, PLUGIN_STYLISTIC } from '../plugins'
import { RULE_JSX_BASE, RULE_JSX_STYLE, RULE_JSX_TYPE_AWARE } from '../rules'
import { defineConfigs, isTrue } from '../utils'
export type JsxConfigOptions = {
tsx?: boolean,
style?: boolean
}
export function jsx(options: JsxConfigOptions = {}) {
const {
tsx = true,
style = true
} = options
const isTsxEnabled = isTrue(tsx)
const isStyleEnabled = isTrue(style)
const files = isTsxEnabled ? [GLOB_JSX_MJSX, GLOB_TSX_MTSX] : [GLOB_JSX_MJSX]
return defineConfigs([
{
name: 'base',
files,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},
plugins: {
[PLUGIN_REACT.meta.name]: PLUGIN_REACT
},
rules: {
...RULE_JSX_BASE,
...RULE_JSX_TYPE_AWARE
}
},
isTsxEnabled
? {
name: 'tsx',
files: [GLOB_TSX_MTSX],
languageOptions: {
parser: PARSER_TS
}
}
: {},
isStyleEnabled
? {
name: 'style',
files,
plugins: {
[PLUGIN_SORT.meta.name]: PLUGIN_SORT,
[PLUGIN_STYLISTIC.meta.name]: PLUGIN_STYLISTIC
},
rules: {
...RULE_JSX_STYLE
}
}
: {}
], 'jsx')
}