forked from antfu/eslint-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolid.ts
88 lines (83 loc) · 2.66 KB
/
solid.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { ensurePackages, interopDefault, toArray } from '../utils'
import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
import { GLOB_JSX, GLOB_TSX } from '../globs'
export async function solid(
options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles & OptionsTypeScriptWithTypes = {},
): Promise<TypedFlatConfigItem[]> {
const {
files = [GLOB_JSX, GLOB_TSX],
overrides = {},
typescript = true,
} = options
await ensurePackages([
'eslint-plugin-solid',
])
const tsconfigPath = options?.tsconfigPath
? toArray(options.tsconfigPath)
: undefined
const isTypeAware = !!tsconfigPath
const [
pluginSolid,
parserTs,
] = await Promise.all([
interopDefault(import('eslint-plugin-solid')),
interopDefault(import('@typescript-eslint/parser')),
] as const)
return [
{
name: 'antfu/solid/setup',
plugins: {
solid: pluginSolid,
},
},
{
files,
languageOptions: {
parser: parserTs,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
...isTypeAware ? { project: tsconfigPath } : {},
},
sourceType: 'module',
},
name: 'antfu/solid/rules',
rules: {
// reactivity
'solid/components-return-once': 'warn',
'solid/event-handlers': ['error', {
// if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`
ignoreCase: false,
// if true, warn when spreading event handlers onto JSX. Enable for Solid < v1.6.
warnOnSpread: false,
}],
// these rules are mostly style suggestions
'solid/imports': 'error',
// identifier usage is important
'solid/jsx-no-duplicate-props': 'error',
'solid/jsx-no-script-url': 'error',
'solid/jsx-no-undef': 'error',
'solid/jsx-uses-vars': 'error',
'solid/no-destructure': 'error',
// security problems
'solid/no-innerhtml': ['error', { allowStatic: true }],
'solid/no-react-deps': 'error',
'solid/no-react-specific-props': 'error',
'solid/no-unknown-namespaces': 'error',
'solid/prefer-for': 'error',
'solid/reactivity': 'warn',
'solid/self-closing-comp': 'error',
'solid/style-prop': ['error', { styleProps: ['style', 'css'] }],
...typescript
? {
'solid/jsx-no-undef': ['error', { typescriptEnabled: true }],
'solid/no-unknown-namespaces': 'off',
}
: {},
// overrides
...overrides,
},
},
]
}