@jimmy.codes/eslint-config
Version:
A simple, modern ESLint config that covers most use cases.
117 lines (114 loc) • 4.61 kB
JavaScript
import { d as GLOB_TSX, o as GLOB_JSX } from "./globs-C5FyFNuk.js";
import { l as hasTypescript, r as hasNext, u as hasVite } from "./has-dependency-lkRo7x2C.js";
import { t as interopDefault } from "./interop-default-DQxo_rHy.js";
import { t as upwarn } from "./upwarn-DItTz7lt.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 reactPluginRules = hasTypescript() ? reactConfigs["strict-type-checked"].rules : reactConfigs.recommended.rules;
return {
...jsxA11yPlugin.flatConfigs.recommended.rules,
...upwarn(reactPluginRules),
"@eslint-react/dom/no-missing-button-type": "error",
"@eslint-react/dom/no-missing-iframe-sandbox": "error",
"@eslint-react/dom/no-string-style-prop": "error",
"@eslint-react/dom/no-unsafe-target-blank": "error",
"@eslint-react/hooks-extra/no-direct-set-state-in-use-effect": "off",
"@eslint-react/jsx-dollar": "off",
"@eslint-react/jsx-key-before-spread": "error",
"@eslint-react/jsx-shorthand-boolean": "error",
"@eslint-react/jsx-shorthand-fragment": "error",
"@eslint-react/naming-convention/component-name": "error",
"@eslint-react/no-children-prop": "error",
"@eslint-react/no-class-component": "error",
"@eslint-react/no-missing-context-display-name": "error",
"@eslint-react/no-unnecessary-key": "error",
"@eslint-react/no-unnecessary-use-callback": "error",
"@eslint-react/no-unnecessary-use-memo": "error",
"@eslint-react/no-unstable-context-value": "error",
"@eslint-react/no-unstable-default-props": "error",
"@eslint-react/no-unused-state": "error",
"@eslint-react/no-useless-fragment": "error",
"@eslint-react/prefer-namespace-import": "error",
"react-compiler/react-compiler": "error",
"react-hooks/component-hook-factories": "error",
"react-hooks/error-boundaries": "error",
"react-hooks/exhaustive-deps": "error",
"react-hooks/globals": "error",
"react-hooks/immutability": "error",
"react-hooks/incompatible-library": "error",
"react-hooks/preserve-manual-memoization": "error",
"react-hooks/purity": "error",
"react-hooks/refs": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/set-state-in-effect": "error",
"react-hooks/set-state-in-render": "error",
"react-hooks/static-components": "error",
"react-hooks/unsupported-syntax": "error",
"react-hooks/use-memo": "error",
"react-hooks/void-use-memo": "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, reactHooksExtraPlugin, reactDomPlugin, reactWebApiPlugin, reactNamingConventionPlugin] = await Promise.all([
interopDefault(import("@eslint-react/eslint-plugin")),
interopDefault(import("eslint-plugin-jsx-a11y")),
interopDefault(import("eslint-plugin-react-hooks")),
interopDefault(import("eslint-plugin-react-refresh")),
interopDefault(import("eslint-plugin-react-compiler")),
interopDefault(import("eslint-plugin-react-hooks-extra")),
interopDefault(import("eslint-plugin-react-dom")),
interopDefault(import("eslint-plugin-react-web-api")),
interopDefault(import("eslint-plugin-react-naming-convention"))
]);
return [{
files: [GLOB_JSX, GLOB_TSX],
languageOptions: {
globals: { ...globals.browser },
parserOptions: {
ecmaFeatures: { jsx: true },
jsxPragma: null
}
},
name: "jimmy.codes/react",
plugins: {
"@eslint-react": reactPlugin,
"@eslint-react/dom": reactDomPlugin,
"@eslint-react/hooks-extra": reactHooksExtraPlugin,
"@eslint-react/naming-convention": reactNamingConventionPlugin,
"@eslint-react/web-api": reactWebApiPlugin,
"jsx-a11y": jsxA11yPlugin,
"react-compiler": reactCompilerPlugin,
"react-hooks": reactHooksPlugin,
"react-refresh": reactRefreshPlugin
},
rules: await reactRules(),
settings: { react: { version: "detect" } }
}];
}
//#endregion
export { reactConfig as default };