Files
Nitro-V3/eslint.hooks.config.mjs
simoleo89 a029ee63cb fix(catalog,ci): catch hook-order violations + add CI gate
Two follow-ups to the CatalogPurchaseWidgetView fix (6bf3366):

1. CatalogItemGridWidgetView had the same shape — four useCallback
   declarations (handleDragStart / handleDragOver / handleDrop /
   handleDragEnd) sat below an `if(!currentPage) return null` early
   return. When currentPage flipped from null to a real page the hook
   count jumped by 4 and React would have thrown "Rendered more hooks
   than during the previous render" the moment any consumer rendered
   the grid in admin mode. Moved the four useCallback declarations
   above the early-return; their bodies are safe pre-load (only
   currentPage?.offers is accessed inside handleDrop, optional-chained
   already).

2. CI gate — the existing GitHub Actions workflow runs `yarn
   typecheck` and `yarn test`, but NOT `yarn eslint`. That's why this
   pattern slipped through twice in a row: ESLint flags it locally
   but no PR check enforces it. Full `yarn eslint` emits ~900
   pre-existing baseline errors (brace-style, indentation,
   recommended TS rules — out of scope for this branch), so a blanket
   step would always fail. Instead added a focused
   `eslint.hooks.config.mjs` + `yarn lint:hooks` script that runs
   ESLint with ONLY `react-hooks/rules-of-hooks: error`. Wired into
   ci.yml between `typecheck` and `test`. The local repo now has
   zero violations of the rule.

3. useSessionSnapshots.test.tsx — added eslint-disable-next-line
   comments on the three lines that intentionally violate the rule
   (they're the assertions that the broken pattern crashes). Without
   the comments the new CI gate would fail on the regression-guard
   suite.

Verification: yarn lint:hooks green, yarn typecheck clean, yarn test
209/209.
2026-05-19 17:57:28 +02:00

44 lines
1.4 KiB
JavaScript

// Minimal ESLint config focused on the Rules of Hooks.
//
// The full eslint.config.mjs runs the project's full lint baseline,
// which currently emits ~900 pre-existing errors (brace style,
// indentation, recommended TS rules) — those are tracked separately
// and would drown a CI signal. This config strips down to just the
// rule we care about as a gate: react-hooks/rules-of-hooks.
//
// Wired up as `yarn lint:hooks` (see package.json) and called from
// .github/workflows/ci.yml so a hook-order violation breaks the
// build the same way a typecheck or test failure would.
import typescriptEslintParser from '@typescript-eslint/parser';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default [
{
files: ['**/*.jsx', '**/*.js', '**/*.tsx', '**/*.ts'],
plugins: {
'react-hooks': reactHooksPlugin
},
languageOptions: {
parser: typescriptEslintParser,
ecmaVersion: 'latest',
parserOptions: {
sourceType: 'module',
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true
}
}
},
rules: {
'react-hooks/rules-of-hooks': 'error'
}
}
];