Skip to content

Commit

Permalink
feat: support solid.js (#441)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
subframe7536 and antfu committed Apr 8, 2024
1 parent 36ec91f commit 6406114
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 1 deletion.
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default antfu(
{
vue: true,
react: true,
solid: true,
svelte: true,
astro: true,
typescript: true,
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"eslint-plugin-solid": "^0.13.2",
"eslint-plugin-svelte": ">=2.35.1",
"prettier-plugin-astro": "^0.13.0",
"prettier-plugin-slidev": "^1.0.5",
Expand Down Expand Up @@ -74,6 +75,9 @@
"eslint-plugin-react-refresh": {
"optional": true
},
"eslint-plugin-solid": {
"optional": true
},
"eslint-plugin-svelte": {
"optional": true
},
Expand Down Expand Up @@ -142,6 +146,7 @@
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-solid": "^0.13.2",
"eslint-plugin-svelte": "2.36.0-next.13",
"eslint-typegen": "^0.2.0",
"esno": "^4.7.0",
Expand Down
51 changes: 51 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scripts/typegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import { flatConfigsToRulesDTS } from 'eslint-typegen/core'
import { builtinRules } from 'eslint/use-at-your-own-risk'
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'
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'

const configs = await combine(
{
Expand All @@ -22,6 +22,7 @@ const configs = await combine(
node(),
perfectionist(),
react(),
solid(),
sortPackageJson(),
stylistic(),
svelte(),
Expand Down
1 change: 1 addition & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from './vue'
export * from './yaml'
export * from './toml'
export * from './astro'
export * from './solid'
88 changes: 88 additions & 0 deletions src/configs/solid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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,
},
},
]
}
10 changes: 10 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
node,
perfectionist,
react,
solid,
sortPackageJson,
sortTsconfig,
stylistic,
Expand Down Expand Up @@ -80,6 +81,7 @@ export function antfu(
gitignore: enableGitignore = true,
isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
react: enableReact = false,
solid: enableSolid = false,
svelte: enableSvelte = false,
typescript: enableTypeScript = isPackageExists('typescript'),
unocss: enableUnoCSS = false,
Expand Down Expand Up @@ -169,6 +171,14 @@ export function antfu(
}))
}

if (enableSolid) {
configs.push(solid({
overrides: getOverrides(options, 'solid'),
tsconfigPath: getOverrides(options, 'typescript').tsconfigPath,
typescript: !!enableTypeScript,
}))
}

if (enableSvelte) {
configs.push(svelte({
overrides: getOverrides(options, 'svelte'),
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,15 @@ export interface OptionsConfig extends OptionsComponentExts {
* @default false
*/
react?: boolean | OptionsOverrides
/**
* Enable solid rules.
*
* Requires installing:
* - `eslint-plugin-solid`
*
* @default false
*/
solid?: boolean | OptionsOverrides

/**
* Enable svelte rules.
Expand Down

0 comments on commit 6406114

Please sign in to comment.