-
Notifications
You must be signed in to change notification settings - Fork 0
/
react.ts
46 lines (41 loc) · 1008 Bytes
/
react.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
import { GLOB_JSX_MJSX, GLOB_TSX_MTSX } from '../globs'
import { PARSER_TS } from '../parsers'
import { PLUGIN_REACT } from '../plugins'
import { RULE_REACT_BASE } from '../rules'
import { defineConfigs, isTrue } from '../utils'
export type ReactConfigOptions = {
tsx?: boolean
}
export function react(options: ReactConfigOptions = {}) {
const { tsx = true } = options
const isTsxEnabled = isTrue(tsx)
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_REACT_BASE
}
},
isTsxEnabled
? {
name: 'tsx',
files: [GLOB_TSX_MTSX],
languageOptions: {
parser: PARSER_TS
}
}
: {}
], 'react')
}