|
| 1 | +import js from "@eslint/js" |
| 2 | +import eslintConfigPrettier from "eslint-config-prettier" |
| 3 | +import tseslint from "typescript-eslint" |
| 4 | +import pluginReactHooks from "eslint-plugin-react-hooks" |
| 5 | +import pluginReact from "eslint-plugin-react" |
| 6 | +import globals from "globals" |
| 7 | +import { config as baseConfig } from "./base.js" |
| 8 | + |
| 9 | +/** |
| 10 | + * Shared eslint configuration for react-based libraries and applications |
| 11 | + * |
| 12 | + * @type {import("eslint").Linter.Config[]} |
| 13 | + */ |
| 14 | +export const config = [ |
| 15 | + // Inherit shared base configuration |
| 16 | + ...baseConfig, |
| 17 | + |
| 18 | + // Core JavaScript linting rules from ESLint |
| 19 | + js.configs.recommended, |
| 20 | + |
| 21 | + // Disables ESLint rules that conflict with Prettier formatting |
| 22 | + eslintConfigPrettier, |
| 23 | + |
| 24 | + // Recommended rules for TypeScript projects |
| 25 | + ...tseslint.configs.recommended, |
| 26 | + |
| 27 | + // Recommended rules for React projects using the flat config API |
| 28 | + pluginReact.configs.flat.recommended, |
| 29 | + |
| 30 | + { |
| 31 | + // Extend language options to include browser and service worker globals |
| 32 | + languageOptions: { |
| 33 | + ...pluginReact.configs.flat.recommended.languageOptions, |
| 34 | + globals: { ...globals.serviceworker, ...globals.browser }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + // React Hooks plugin configuration |
| 39 | + plugins : { "react-hooks": pluginReactHooks }, |
| 40 | + settings : { |
| 41 | + // Automatically detect the installed React version |
| 42 | + react: { version: "detect" }, |
| 43 | + }, |
| 44 | + rules : { |
| 45 | + // Include recommended rules for React Hooks |
| 46 | + ...pluginReactHooks.configs.recommended.rules, |
| 47 | + |
| 48 | + // Disable rule requiring React to be in scope for JSX |
| 49 | + // Not needed with the new JSX transform (React 17+) |
| 50 | + "react/react-in-jsx-scope": "off", |
| 51 | + }, |
| 52 | + }, |
| 53 | +] |
0 commit comments