|
| 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 | +} |
0 commit comments