import js from '@eslint/js'; import globals from 'globals'; import reactHooks from 'eslint-plugin-react-hooks'; import reactRefresh from 'eslint-plugin-react-refresh'; import tseslint from 'typescript-eslint'; import prettier from 'eslint-config-prettier'; // ESLint 9 flat config. Order matters: `prettier` must come last so it can // switch off any stylistic rules that would fight the formatter — ESLint owns // code-correctness, Prettier owns formatting. export default tseslint.config( { ignores: ['dist', 'node_modules', 'coverage'] }, { files: ['**/*.{ts,tsx}'], extends: [js.configs.recommended, ...tseslint.configs.recommended], languageOptions: { ecmaVersion: 2022, globals: globals.browser, }, plugins: { 'react-hooks': reactHooks, 'react-refresh': reactRefresh, }, rules: { ...reactHooks.configs.recommended.rules, 'react-refresh/only-export-components': ['warn', { allowConstantExport: true }], }, }, { // Test + setup files also touch Node globals (process, etc.) and use // jsdom; allow both global sets. files: ['**/*.test.{ts,tsx}', 'src/test/**/*.ts'], languageOptions: { globals: { ...globals.browser, ...globals.node }, }, }, { // Context files intentionally export a Provider component *and* its hook // from the same module — the standard React Context pattern. The // react-refresh rule flags this; the trade-off (marginally less optimal // HMR) isn't worth splitting every context into two files. files: ['src/hooks/**/*.tsx'], rules: { 'react-refresh/only-export-components': 'off', }, }, { // Config files run in Node. files: ['*.config.{js,ts}'], languageOptions: { globals: globals.node, }, }, prettier, );