UNPKG

@sylphlab/eslint-config-sylph-react

Version:
1 lines 5.86 kB
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import globals from 'globals';\nimport reactPlugin from 'eslint-plugin-react';\nimport reactHooksPlugin from 'eslint-plugin-react-hooks';\nimport jsxA11yPlugin from 'eslint-plugin-jsx-a11y';\nimport { sylph as sylphBaseConfig } from '@sylphlab/eslint-config-sylph'; // Import the base config array\nimport type { Linter } from 'eslint';\n\n// Define type alias for FlatConfig for better readability\ntype Config = Linter.Config; // Use Linter.Config instead of deprecated Linter.FlatConfig\n\n/**\n * Sylph ESLint Configuration for React Projects (Flat Config)\n *\n * Extends the base @sylphlab/eslint-config-sylph configuration with\n * rules specific to React, React Hooks, and JSX A11y.\n */\nexport const react: Config[] = [ // Explicitly type the constant\n // 1. Inherit Base Configuration\n // Includes core JS, TS, Unicorn, Import, Functional, Security, Sonar, Promise, RegExp, Prettier rules\n ...sylphBaseConfig,\n\n // 2. React Specific Configuration\n {\n files: ['**/*.{jsx,tsx}'], // Apply React rules only to JSX/TSX files\n plugins: {\n 'react': reactPlugin as any,\n 'react-hooks': reactHooksPlugin as any,\n 'jsx-a11y': jsxA11yPlugin as any,\n },\n languageOptions: {\n parserOptions: {\n ecmaFeatures: { jsx: true }, // Enable JSX parsing\n },\n globals: {\n ...globals.browser, // Add browser globals common in React apps\n },\n },\n settings: {\n react: {\n version: 'detect', // Automatically detect React version\n },\n },\n rules: {\n // --- React Plugin Recommended Rules ---\n // We manually include rules from recommended sets as flat config doesn't spread them automatically\n ...reactPlugin.configs.recommended.rules,\n ...reactPlugin.configs['jsx-runtime'].rules, // For the new JSX transform\n ...reactHooksPlugin.configs.recommended.rules,\n ...jsxA11yPlugin.configs.recommended.rules,\n\n // --- Rule Overrides & Additions for React ---\n 'react/prop-types': 'off', // Disable prop-types rule, rely on TypeScript\n 'react/react-in-jsx-scope': 'off', // Disable rule requiring React import (new JSX transform)\n 'react/jsx-filename-extension': ['error', { extensions: ['.jsx', '.tsx'] }], // Allow JSX only in .jsx/.tsx\n 'react/jsx-props-no-spreading': 'off', // Allow prop spreading (common pattern)\n 'react/require-default-props': 'off', // Default props are less common with TS\n 'react/jsx-uses-react': 'off', // Covered by jsx-runtime config\n 'react/jsx-uses-vars': 'error', // Ensure vars used in JSX are marked as used\n\n // --- JSX A11y Overrides ---\n 'jsx-a11y/anchor-is-valid': 'off', // Often handled by routers like React Router\n 'jsx-a11y/label-has-associated-control': ['error', { // Stricter label association\n assert: 'either', // Allow either nesting or htmlFor\n }],\n\n // --- Unicorn Overrides for React ---\n // Allow PascalCase for component filenames\n 'unicorn/filename-case': ['error', {\n cases: { pascalCase: true, kebabCase: true },\n ignore: [\n /^\\.?.*rc\\.[cm]?js$/,\n /^[a-zA-Z]+(?:[-.][a-zA-Z]+)*\\.config\\.[cm]?[jt]s$/,\n /^[a-zA-Z]+(?:[-.][a-zA-Z]+)*\\.setup\\.[cm]?[jt]s$/,\n /\\.d\\.ts$/,\n 'vite-env.d.ts',\n /^\\.env(?:\\.\\w+)?$/,\n // Keep common non-component names kebab-case\n 'index\\.[jt]sx?$',\n 'main\\.[jt]sx?$',\n 'app\\.[jt]sx?$', // Allow app.jsx/tsx\n 'router\\.[jt]sx?$', // Allow router.jsx/tsx\n 'store\\.[jt]sx?$', // Allow store.jsx/tsx\n 'service-worker\\.[jt]sx?$',\n 'registerServiceWorker\\.[jt]sx?$',\n ],\n }],\n // Allow 'Props' and 'Ref' abbreviations common in React\n 'unicorn/prevent-abbreviations': ['error', {\n allowList: { Props: true, Ref: true }\n }],\n },\n },\n]; // Remove satisfies\n\n// Export the config directly\nexport default react;"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,UAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAoB,wBACpBC,EAAwB,oCACxBC,EAA6B,0CAC7BC,EAA0B,uCAC1BC,EAAyC,yCAY5BN,EAAkB,CAG3B,GAAG,EAAAO,MAGH,CACI,MAAO,CAAC,gBAAgB,EACxB,QAAS,CACL,MAAS,EAAAC,QACT,cAAe,EAAAC,QACf,WAAY,EAAAC,OAChB,EACA,gBAAiB,CACb,cAAe,CACX,aAAc,CAAE,IAAK,EAAK,CAC9B,EACA,QAAS,CACL,GAAG,EAAAC,QAAQ,OACf,CACJ,EACA,SAAU,CACN,MAAO,CACH,QAAS,QACb,CACJ,EACA,MAAO,CAGH,GAAG,EAAAH,QAAY,QAAQ,YAAY,MACnC,GAAG,EAAAA,QAAY,QAAQ,aAAa,EAAE,MACtC,GAAG,EAAAC,QAAiB,QAAQ,YAAY,MACxC,GAAG,EAAAC,QAAc,QAAQ,YAAY,MAGrC,mBAAoB,MACpB,2BAA4B,MAC5B,+BAAgC,CAAC,QAAS,CAAE,WAAY,CAAC,OAAQ,MAAM,CAAE,CAAC,EAC1E,+BAAgC,MAChC,8BAA+B,MAC/B,uBAAwB,MACxB,sBAAuB,QAGvB,2BAA4B,MAC5B,wCAAyC,CAAC,QAAS,CAC/C,OAAQ,QACZ,CAAC,EAID,wBAAyB,CAAC,QAAS,CAC/B,MAAO,CAAE,WAAY,GAAM,UAAW,EAAK,EAC3C,OAAQ,CACJ,qBACA,oDACA,mDACA,WACA,gBACA,oBAEA,iBACA,gBACA,eACA,kBACA,iBACA,0BACA,gCACJ,CACJ,CAAC,EAED,gCAAiC,CAAC,QAAS,CACvC,UAAW,CAAE,MAAO,GAAM,IAAK,EAAK,CACxC,CAAC,CACL,CACJ,CACJ,EAGOX,EAAQC","names":["index_exports","__export","index_default","react","__toCommonJS","import_globals","import_eslint_plugin_react","import_eslint_plugin_react_hooks","import_eslint_plugin_jsx_a11y","import_eslint_config_sylph","sylphBaseConfig","reactPlugin","reactHooksPlugin","jsxA11yPlugin","globals"]}