Skip to content

Commit 6406114

Browse files
subframe7536antfu
andauthoredApr 8, 2024··
feat: support solid.js (#441)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 36ec91f commit 6406114

File tree

8 files changed

+167
-1
lines changed

8 files changed

+167
-1
lines changed
 

‎eslint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default antfu(
1212
{
1313
vue: true,
1414
react: true,
15+
solid: true,
1516
svelte: true,
1617
astro: true,
1718
typescript: true,

‎package.json

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"eslint-plugin-react": "^7.33.2",
4848
"eslint-plugin-react-hooks": "^4.6.0",
4949
"eslint-plugin-react-refresh": "^0.4.4",
50+
"eslint-plugin-solid": "^0.13.2",
5051
"eslint-plugin-svelte": ">=2.35.1",
5152
"prettier-plugin-astro": "^0.13.0",
5253
"prettier-plugin-slidev": "^1.0.5",
@@ -74,6 +75,9 @@
7475
"eslint-plugin-react-refresh": {
7576
"optional": true
7677
},
78+
"eslint-plugin-solid": {
79+
"optional": true
80+
},
7781
"eslint-plugin-svelte": {
7882
"optional": true
7983
},
@@ -142,6 +146,7 @@
142146
"eslint-plugin-react": "^7.34.1",
143147
"eslint-plugin-react-hooks": "^4.6.0",
144148
"eslint-plugin-react-refresh": "^0.4.6",
149+
"eslint-plugin-solid": "^0.13.2",
145150
"eslint-plugin-svelte": "2.36.0-next.13",
146151
"eslint-typegen": "^0.2.0",
147152
"esno": "^4.7.0",

‎pnpm-lock.yaml

+51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎scripts/typegen.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs/promises'
22
import { flatConfigsToRulesDTS } from 'eslint-typegen/core'
33
import { builtinRules } from 'eslint/use-at-your-own-risk'
4-
import { astro, combine, comments, formatters, imports, javascript, jsdoc, jsonc, markdown, node, perfectionist, react, sortPackageJson, stylistic, svelte, test, toml, typescript, unicorn, unocss, vue, yaml } from '../src'
4+
import { astro, combine, comments, formatters, imports, javascript, jsdoc, jsonc, markdown, node, perfectionist, react, solid, sortPackageJson, stylistic, svelte, test, toml, typescript, unicorn, unocss, vue, yaml } from '../src'
55

66
const configs = await combine(
77
{
@@ -22,6 +22,7 @@ const configs = await combine(
2222
node(),
2323
perfectionist(),
2424
react(),
25+
solid(),
2526
sortPackageJson(),
2627
stylistic(),
2728
svelte(),

‎src/configs/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export * from './vue'
2020
export * from './yaml'
2121
export * from './toml'
2222
export * from './astro'
23+
export * from './solid'

‎src/configs/solid.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { ensurePackages, interopDefault, toArray } from '../utils'
2+
import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
3+
import { GLOB_JSX, GLOB_TSX } from '../globs'
4+
5+
export async function solid(
6+
options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles & OptionsTypeScriptWithTypes = {},
7+
): Promise<TypedFlatConfigItem[]> {
8+
const {
9+
files = [GLOB_JSX, GLOB_TSX],
10+
overrides = {},
11+
typescript = true,
12+
} = options
13+
14+
await ensurePackages([
15+
'eslint-plugin-solid',
16+
])
17+
18+
const tsconfigPath = options?.tsconfigPath
19+
? toArray(options.tsconfigPath)
20+
: undefined
21+
const isTypeAware = !!tsconfigPath
22+
23+
const [
24+
pluginSolid,
25+
parserTs,
26+
] = await Promise.all([
27+
interopDefault(import('eslint-plugin-solid')),
28+
interopDefault(import('@typescript-eslint/parser')),
29+
] as const)
30+
31+
return [
32+
{
33+
name: 'antfu/solid/setup',
34+
plugins: {
35+
solid: pluginSolid,
36+
},
37+
},
38+
{
39+
files,
40+
languageOptions: {
41+
parser: parserTs,
42+
parserOptions: {
43+
ecmaFeatures: {
44+
jsx: true,
45+
},
46+
...isTypeAware ? { project: tsconfigPath } : {},
47+
},
48+
sourceType: 'module',
49+
},
50+
name: 'antfu/solid/rules',
51+
rules: {
52+
// reactivity
53+
'solid/components-return-once': 'warn',
54+
'solid/event-handlers': ['error', {
55+
// if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`
56+
ignoreCase: false,
57+
// if true, warn when spreading event handlers onto JSX. Enable for Solid < v1.6.
58+
warnOnSpread: false,
59+
}],
60+
// these rules are mostly style suggestions
61+
'solid/imports': 'error',
62+
// identifier usage is important
63+
'solid/jsx-no-duplicate-props': 'error',
64+
'solid/jsx-no-script-url': 'error',
65+
'solid/jsx-no-undef': 'error',
66+
'solid/jsx-uses-vars': 'error',
67+
'solid/no-destructure': 'error',
68+
// security problems
69+
'solid/no-innerhtml': ['error', { allowStatic: true }],
70+
'solid/no-react-deps': 'error',
71+
'solid/no-react-specific-props': 'error',
72+
'solid/no-unknown-namespaces': 'error',
73+
'solid/prefer-for': 'error',
74+
'solid/reactivity': 'warn',
75+
'solid/self-closing-comp': 'error',
76+
'solid/style-prop': ['error', { styleProps: ['style', 'css'] }],
77+
...typescript
78+
? {
79+
'solid/jsx-no-undef': ['error', { typescriptEnabled: true }],
80+
'solid/no-unknown-namespaces': 'off',
81+
}
82+
: {},
83+
// overrides
84+
...overrides,
85+
},
86+
},
87+
]
88+
}

‎src/factory.ts

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
node,
1717
perfectionist,
1818
react,
19+
solid,
1920
sortPackageJson,
2021
sortTsconfig,
2122
stylistic,
@@ -80,6 +81,7 @@ export function antfu(
8081
gitignore: enableGitignore = true,
8182
isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
8283
react: enableReact = false,
84+
solid: enableSolid = false,
8385
svelte: enableSvelte = false,
8486
typescript: enableTypeScript = isPackageExists('typescript'),
8587
unocss: enableUnoCSS = false,
@@ -169,6 +171,14 @@ export function antfu(
169171
}))
170172
}
171173

174+
if (enableSolid) {
175+
configs.push(solid({
176+
overrides: getOverrides(options, 'solid'),
177+
tsconfigPath: getOverrides(options, 'typescript').tsconfigPath,
178+
typescript: !!enableTypeScript,
179+
}))
180+
}
181+
172182
if (enableSvelte) {
173183
configs.push(svelte({
174184
overrides: getOverrides(options, 'svelte'),

‎src/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,15 @@ export interface OptionsConfig extends OptionsComponentExts {
290290
* @default false
291291
*/
292292
react?: boolean | OptionsOverrides
293+
/**
294+
* Enable solid rules.
295+
*
296+
* Requires installing:
297+
* - `eslint-plugin-solid`
298+
*
299+
* @default false
300+
*/
301+
solid?: boolean | OptionsOverrides
293302

294303
/**
295304
* Enable svelte rules.

0 commit comments

Comments
 (0)
Please sign in to comment.