@jimmy.codes/eslint-config
Version:
A simple, modern ESLint config that covers most use cases.
126 lines (123 loc) • 4.91 kB
JavaScript
import { d as GLOB_TSX, o as GLOB_JSX } from "./globs-uKx5b8lV.mjs";
import { l as hasTypescript, r as hasNext, u as hasVite } from "./has-dependency-BreXO1rF.mjs";
import { n as extractOptions, t as interopDefault } from "./interop-default-CKeWA-H9.mjs";
import { t as upwarn } from "./astro-BnZ2LIR3.mjs";
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 (options) => {
const [{ configs: reactConfigs }, { flatConfigs: jsxA11yConfigs }, { configs: reactDomConfigs }, { configs: reactHooksExtraConfigs }, { configs: reactWebApiConfigs }, { configs: reactNamingConventionConfigs }] = await Promise.all([
interopDefault(import("eslint-plugin-react-x")),
interopDefault(import("eslint-plugin-jsx-a11y")),
interopDefault(import("eslint-plugin-react-dom")),
interopDefault(import("eslint-plugin-react-hooks-extra")),
interopDefault(import("eslint-plugin-react-web-api")),
interopDefault(import("eslint-plugin-react-naming-convention"))
]);
const isUsingNextjs = hasNext();
const isUsingVite = hasVite();
const isUsingTypesScript = hasTypescript();
const reactPluginRules = isUsingTypesScript ? reactConfigs["strict-type-checked"].rules : reactConfigs.strict.rules;
const reactDomPluginRules = isUsingTypesScript ? {
...reactDomConfigs.strict.rules,
"react-dom/no-string-style-prop": "off",
"react-dom/no-unknown-property": "off"
} : {
...reactDomConfigs.strict.rules,
"react-dom/no-string-style-prop": "error",
"react-dom/no-unknown-property": ["error", { requireDataLowercase: true }]
};
return {
...jsxA11yConfigs.recommended.rules,
...upwarn(reactPluginRules),
...upwarn(reactDomPluginRules),
...upwarn(reactHooksExtraConfigs.recommended.rules),
...upwarn(reactWebApiConfigs.recommended.rules),
...upwarn(reactNamingConventionConfigs.recommended.rules),
"react-compiler/react-compiler": "error",
"react-hooks-extra/no-direct-set-state-in-use-effect": "off",
"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-naming-convention/component-name": "error",
"react-refresh/only-export-components": ["warn", {
allowConstantExport: isUsingVite,
allowExportNames: isUsingNextjs ? nextAllowedExportNames : []
}],
"react-x/jsx-dollar": "off",
"react-x/jsx-shorthand-boolean": "error",
"react-x/jsx-shorthand-fragment": "error",
"react-x/no-missing-context-display-name": "error",
"react-x/prefer-namespace-import": "error",
...options?.overrides
};
};
//#endregion
//#region src/configs/react.ts
async function reactConfig(options) {
const extractedOptions = extractOptions(options);
const [reactPlugin, jsxA11yPlugin, reactHooksPlugin, reactRefreshPlugin, reactCompilerPlugin, reactHooksExtraPlugin, reactDomPlugin, reactWebApiPlugin, reactNamingConventionPlugin] = await Promise.all([
interopDefault(import("eslint-plugin-react-x")),
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: {
"jsx-a11y": jsxA11yPlugin,
"react-compiler": reactCompilerPlugin,
"react-dom": reactDomPlugin,
"react-hooks": reactHooksPlugin,
"react-hooks-extra": reactHooksExtraPlugin,
"react-naming-convention": reactNamingConventionPlugin,
"react-refresh": reactRefreshPlugin,
"react-web-api": reactWebApiPlugin,
"react-x": reactPlugin
},
rules: await reactRules(extractedOptions),
settings: { react: { version: "detect" } }
}];
}
//#endregion
export { reactConfig as default };