Files
zeekayandHanzo Dev df3d6ad05d fix(lint): let the React Compiler's checks warn
eslint-config-next went from 15 to 16 in the version sweep and took
eslint-plugin-react-hooks from 5 to 7. Next spreads the plugin's
recommended set, and 7's set is the two rules of hooks plus twelve React
Compiler checks at error. Nothing in the lint config asked for them; they
arrived with the bump and failed 39 places in packages/lib and packages/ui
that were written before the compiler, 24 of them setState in an effect and
11 a ref read during render.

Making those pass means reworking when components render, and nothing here
can test that: there is no DOM in the test runners. So the compiler's checks
report as warnings — listed on every run, blocking nothing — and the rules
of hooks stay errors. react-hooks.test.cjs resolves the shipped config for a
component file and holds both; without the new entry it fails on
set-state-in-effect.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-19 04:16:59 -07:00

47 lines
1.2 KiB
JavaScript

const assert = require('node:assert/strict');
const path = require('node:path');
const { test } = require('node:test');
const { ESLint } = require('eslint');
const config = require('../index.cjs');
// The rules eslint applies to a component file under the config as shipped.
const rulesFor = async (filename) => {
const eslint = new ESLint({
cwd: path.join(__dirname, '..'),
overrideConfigFile: true,
overrideConfig: config,
});
const resolved = await eslint.calculateConfigForFile(filename);
return resolved.rules;
};
const ERROR = 2;
const WARN = 1;
test('breaking a rule of hooks fails the lint', async () => {
const rules = await rulesFor('probe.tsx');
assert.equal(rules['react-hooks/rules-of-hooks'][0], ERROR);
});
test('the React Compiler checks warn and block nothing', async () => {
const rules = await rulesFor('probe.tsx');
const compilerChecks = Object.keys(rules).filter(
(rule) =>
rule.startsWith('react-hooks/') &&
rule !== 'react-hooks/rules-of-hooks' &&
rule !== 'react-hooks/exhaustive-deps',
);
assert.ok(compilerChecks.includes('react-hooks/set-state-in-effect'));
for (const rule of compilerChecks) {
assert.ok(rules[rule][0] <= WARN, `${rule} is an error`);
}
});