@jimmy.codes/eslint-config
Version:
A simple, modern ESLint config that covers most use cases.
127 lines (123 loc) • 3.73 kB
JavaScript
import {
upwarn
} from "./chunk-BDIXPIKB.js";
import {
hasNext,
hasTypescript,
hasVite
} from "./chunk-OCS4JNPP.js";
import {
interopDefault
} from "./chunk-72FT76PY.js";
import {
GLOB_JSX,
GLOB_TSX
} from "./chunk-N5KZEOXT.js";
// src/configs/react.ts
import globals from "globals";
// src/rules/react.ts
var nextAllowedExportNames = [
"dynamic",
"dynamicParams",
"revalidate",
"fetchCache",
"runtime",
"preferredRegion",
"maxDuration",
"config",
"generateStaticParams",
"metadata",
"generateMetadata",
"viewport",
"generateViewport"
];
var 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 : []
}
]
};
};
// 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"
}
}
}
];
}
export {
reactConfig as default
};