-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.ts
71 lines (66 loc) · 1.62 KB
/
javascript.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
70
71
import { GLOBALS_ES2024 } from '../globals'
import { GLOB_JS_MJS, GLOB_JSX_MJSX } from '../globs'
import { PLUGIN_IMPORT, PLUGIN_SORT, PLUGIN_STYLISTIC, PLUGIN_UNICORN } from '../plugins'
import { RULE_JS_BASE, RULE_JS_STYLE } from '../rules'
import { defineConfigs, isTrue } from '../utils'
export type JavaScriptConfigOptions = {
jsx?: boolean,
style?: boolean
}
export function javascript(options: JavaScriptConfigOptions = {}) {
const {
jsx = true,
style = true
} = options
const isJsxEnabled = isTrue(jsx)
const isStyleEnabled = isTrue(style)
const files = isJsxEnabled ? [GLOB_JS_MJS, GLOB_JSX_MJSX] : [GLOB_JS_MJS]
return defineConfigs([
{
name: 'base',
files,
languageOptions: {
ecmaVersion: 'latest',
globals: {
...GLOBALS_ES2024
},
parserOptions: {
ecmaVersion: 'latest'
}
},
plugins: {
[PLUGIN_UNICORN.meta.name]: PLUGIN_UNICORN,
[PLUGIN_IMPORT.meta.name]: PLUGIN_IMPORT
},
rules: {
...RULE_JS_BASE
}
},
isJsxEnabled
? {
name: 'jsx',
files: [GLOB_JSX_MJSX],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
}
}
: {},
isStyleEnabled
? {
name: 'style',
files,
plugins: {
[PLUGIN_SORT.meta.name]: PLUGIN_SORT,
[PLUGIN_STYLISTIC.meta.name]: PLUGIN_STYLISTIC
},
rules: {
...RULE_JS_STYLE
}
}
: {}
], 'javascript')
}