UNPKG

@jimmy.codes/eslint-config

Version:

A simple, modern ESLint config that covers most use cases.

92 lines (89 loc) 3.43 kB
import { GLOB_JSX, GLOB_TSX } from "./constants-dep165g5.js"; import { hasNext, hasTypescript, hasVite } from "./has-dependency-B3Fi8OzA.js"; import { interopDefault } from "./interop-default-D4l3hsYQ.js"; import { upwarn } from "./upwarn-C7t3ub-R.js"; import globals from "globals"; //#region src/rules/react.ts const nextAllowedExportNames = [ "dynamic", "dynamicParams", "revalidate", "fetchCache", "runtime", "preferredRegion", "maxDuration", "config", "generateStaticParams", "metadata", "generateMetadata", "viewport", "generateViewport" ]; const reactRules = async () => { const [{ configs: reactConfigs }, jsxA11yPlugin] = await Promise.all([interopDefault(import("@eslint-react/eslint-plugin")), interopDefault(import("eslint-plugin-jsx-a11y"))]); const isUsingNextjs = hasNext(); const isUsingVite = hasVite(); const isUsingTypesScript = hasTypescript(); const reactPluginRules = isUsingTypesScript ? reactConfigs["recommended-type-checked"].rules : reactConfigs.recommended.rules; return { ...jsxA11yPlugin.configs.recommended.rules, ...upwarn(reactPluginRules), "@eslint-react/avoid-shorthand-boolean": "off", "@eslint-react/avoid-shorthand-fragment": "off", "@eslint-react/hooks-extra/no-unnecessary-use-callback": "error", "@eslint-react/hooks-extra/no-unnecessary-use-memo": "error", "@eslint-react/hooks-extra/no-unnecessary-use-prefix": "error", "@eslint-react/hooks-extra/prefer-use-state-lazy-initialization": "error", "@eslint-react/no-children-prop": "error", "@eslint-react/no-complex-conditional-rendering": "error", "@eslint-react/no-useless-fragment": "error", "@eslint-react/prefer-react-namespace-import": "error", "@eslint-react/prefer-shorthand-boolean": "error", "@eslint-react/prefer-shorthand-fragment": "error", "react-compiler/react-compiler": "error", "react-hooks/exhaustive-deps": "error", "react-hooks/rules-of-hooks": "error", "react-refresh/only-export-components": ["warn", { allowConstantExport: isUsingVite, allowExportNames: isUsingNextjs ? nextAllowedExportNames : [] }] }; }; //#endregion //#region src/configs/react.ts async function reactConfig() { const [reactPlugin, jsxA11yPlugin, reactHooksPlugin, reactRefreshPlugin, reactCompilerPlugin] = await Promise.all([ interopDefault(import("@eslint-react/eslint-plugin")), interopDefault(import("eslint-plugin-jsx-a11y")), import("eslint-plugin-react-hooks"), interopDefault(import("eslint-plugin-react-refresh")), import("eslint-plugin-react-compiler") ]); const reactPlugins = reactPlugin.configs.all.plugins; return [{ files: [GLOB_JSX, GLOB_TSX], languageOptions: { globals: { ...globals.browser }, parserOptions: { ecmaFeatures: { jsx: true }, jsxPragma: null } }, name: "jimmy.codes/react", plugins: { "@eslint-react": reactPlugins["@eslint-react"], "@eslint-react/dom": reactPlugins["@eslint-react/dom"], "@eslint-react/hooks-extra": reactPlugins["@eslint-react/hooks-extra"], "@eslint-react/naming-convention": reactPlugins["@eslint-react/naming-convention"], "@eslint-react/web-api": reactPlugins["@eslint-react/web-api"], "jsx-a11y": jsxA11yPlugin, "react-compiler": reactCompilerPlugin, "react-hooks": reactHooksPlugin, "react-refresh": reactRefreshPlugin }, rules: await reactRules(), settings: { react: { version: "detect" } } }]; } //#endregion export { reactConfig as default };