eslint-plugin-react-hooks 패치 업데이트 후 set-state-in-effect 에러가 생길 때: FlatCompat은 플러그인을 루트에서 찾는다
선언한 적 없는 react-hooks/set-state-in-effect 룰이 error로 켜져 lint가 깨진다면 원인은 FlatCompat의 플러그인 해석 위치일 수 있습니다. legacy extends가 루트에 설치된 플러그인 버전을 쓰는 이유와, 머지 전에 A/B로 확인하는 방법을 정리했습니다.
Dependabot이 eslint-plugin-react-hooks를 7.0.1 → 7.1.1로 올리는 PR을 만들었습니다. 바뀐 건 package.json 한 줄과 lock 파일 한 항목뿐이고, 새 의존성도 네이티브 모듈도 없습니다. 그런데 lint 결과가 이렇게 바뀌었습니다.
7.0.1 : 0 errors / 101 warnings
7.1.1 : 6 errors / 101 warnings ← react-hooks/set-state-in-effect
set-state-in-effect는 프로젝트 설정에서 한 번도 선언한 적 없는 룰이었습니다. 그런데 심각도가 error였습니다.
먼저 결론
FlatCompat으로 legacy shareable config(예:eslint-config-expo)를 불러오면, 그 config 안의extends: ['plugin:react-hooks/recommended']같은 문자열 참조는 프로젝트 루트 기준으로 해석됩니다.- 그래서 shareable config가 자기 안에 v5를 고정해 뒀어도, 실제로는 루트에 설치된 v7의 recommended 프리셋이 적용됩니다.
- v7 recommended는 룰 16개, 대부분
error입니다. 프로젝트가 몇 개만warn으로 내려놨다면 나머지는 선언 없이error로 살아 있습니다. - 패치 업데이트가 에러를 만든 건 룰이 바뀌어서가 아니라 검출력이 좋아져서입니다.
CI는 초록인데 로컬에서만 막히는 이유
lint job이 CI에 없는 리포라면 이 PR의 체크는 전부 통과합니다. 대신 lint-staged가 커밋할 파일에 eslint --fix를 돌립니다. set-state-in-effect는 자동 수정이 없어서 exit 1이 나고, 그 파일을 건드리는 커밋이 pre-commit에서 막힙니다. CI는 멀쩡하고 개발자 로컬에서만 터지는 모양으로 드러납니다.
원인: 문자열 참조는 "읽는 쪽"에서 해석된다
shareable config는 flat config용 진입점과 legacy용 진입점을 따로 두는 경우가 많습니다. eslint-config-expo(v55)를 예로 들면 이렇습니다.
// flat/utils/react.js — flat config 진입점
const pluginReactHooks = require('eslint-plugin-react-hooks');
// ↑ eslint-config-expo 안에서 require → 자기 node_modules에 고정한 v5를 잡는다
// utils/react.js — legacy 진입점
module.exports = {
extends: ['plugin:react-hooks/recommended'],
// ↑ 문자열. 해석하는 위치가 config 주인이 아니라 "읽는 쪽"이다
};
FlatCompat은 legacy 진입점을 읽고, plugin:react-hooks/recommended라는 문자열을 baseDirectory(보통 프로젝트 루트) 기준으로 찾습니다.
eslint.config.js ...compat.extends('expo')
└→ eslint-config-expo/utils/react.js extends: ['plugin:react-hooks/recommended']
└→ FlatCompat가 프로젝트 루트에서 플러그인을 찾음
└→ 루트에 설치된 eslint-plugin-react-hooks v7의 recommended
즉 패키지가 자기 안에 v5를 고정해 둔 것은 flat 진입점에서만 의미가 있습니다.
두 버전의 recommended 차이는 큽니다.
| 플러그인 | recommended 룰 수 |
|---|---|
| v5 | 2개 (rules-of-hooks error, exhaustive-deps warn) |
| v7 | 16개, 대부분 error |
v7 recommended에는 React Compiler 기반 룰이 많이 들어 있습니다.
rules-of-hooks error set-state-in-effect error
exhaustive-deps warn error-boundaries error
static-components error purity error
use-memo error set-state-in-render error
preserve-manual-memoization error unsupported-syntax warn
incompatible-library warn config error
immutability error gating error
globals error refs error
왜 패치 업데이트가 새 에러를 만들었나
7.0.1과 7.1.1의 룰 목록과 심각도를 직접 비교해 보면 거의 바뀐 게 없습니다.
룰 개수: 29 → 29
이름 변경: automatic-effect-dependencies → exhaustive-effect-dependencies
이름 변경: fire → memo-dependencies
recommended 심각도 차이: component-hook-factories 프리셋에서 제거, 1건뿐
바뀐 건 검출력입니다. 7.1.0 릴리스 노트에는 "set-state-in-effect 검증의 false negative를 줄였다"는 항목이 있습니다. 위반은 원래부터 있었고, 이전 버전이 찾지 못했을 뿐입니다.
React Compiler 기반 룰에서는 patch·minor 버전 업데이트도 lint 결과를 바꿉니다. error로 방치된 룰은 잠재 부채이고, 언제 터질지는 플러그인 릴리스가 정합니다.
확인하는 법
1. 실제로 켜진 룰 보기
설정 파일을 읽는 것보다 최종 적용값을 보는 게 정확합니다.
npx eslint --print-config src/App.tsx | grep react-hooks
플러그인 프리셋 자체를 보고 싶다면 이렇게 덤프합니다.
// dump-preset.js
const m = require('eslint-plugin-react-hooks');
for (const [name, cfg] of Object.entries(m.configs)) {
const arr = Array.isArray(cfg) ? cfg : [cfg];
const rules = Object.assign({}, ...arr.map((c) => c.rules || {}));
console.log(name, JSON.stringify(rules, null, 1));
}
2. 머지 전에 두 버전을 비교하기 (lock 파일은 그대로)
후보 버전을 프로젝트 node_modules 안에 따로 풀어 두고 lint를 두 번 돌려 비교합니다.
npm pack eslint-plugin-react-hooks@7.1.1
tar xzf eslint-plugin-react-hooks-7.1.1.tgz # → package/
cp -R package node_modules/.candidate
함정이 두 개 있습니다.
- 후보 폴더는 반드시
node_modules/안에 둡니다./tmp같은 바깥에 두면 Node가 부모 폴더를 거슬러 올라가며 의존성을 찾다가@babel/core같은 패키지를 못 찾고MODULE_NOT_FOUND로 죽습니다. - 루트로 끌어올려지지 않은 의존성은 따로 채워야 합니다. 원래 설치본의
node_modules/를 복사해 넣습니다. 두 버전의 의존성 범위가 같다면 실제 설치 결과와 같습니다.
cp -R node_modules/eslint-plugin-react-hooks/node_modules node_modules/.candidate/node_modules
후보 폴더를 만들어 두기만 해서는 비교가 되지 않습니다. ESLint는 여전히 원래 경로(node_modules/eslint-plugin-react-hooks)의 플러그인을 불러오기 때문입니다. 후보 버전을 원래 이름 자리에 잠시 바꿔 끼워야 합니다.
# 1) 현재 버전으로 측정
npx eslint . -f json -o out-7.0.1.json
# 2) 후보를 원래 자리에 바꿔 끼우기
mv node_modules/eslint-plugin-react-hooks node_modules/.orig-react-hooks
mv node_modules/.candidate node_modules/eslint-plugin-react-hooks
node -p "require('eslint-plugin-react-hooks/package.json').version" # 7.1.1이 나와야 함
npx eslint . -f json -o out-7.1.1.json
# 3) 원래대로 되돌리기
rm -rf node_modules/eslint-plugin-react-hooks
mv node_modules/.orig-react-hooks node_modules/eslint-plugin-react-hooks
node -p "require('eslint-plugin-react-hooks/package.json').version" # 7.0.1이 나와야 함
node -p로 실제로 불러오는 버전을 꼭 확인합니다. 이 확인이 없으면 같은 버전을 두 번 재고 "차이가 없다"고 결론 내리기 쉽습니다.
번거롭다면 임시 브랜치나 git worktree에서 pnpm add -D eslint-plugin-react-hooks@7.1.1로 실제 설치해 비교하고, 끝나면 브랜치를 버리는 방법도 있습니다.
두 결과 파일에서 룰별 개수를 비교합니다.
const r = require('./out-7.1.1.json'); // out-7.0.1.json도 같은 방식으로
const c = {};
for (const f of r) for (const m of f.messages) c[m.ruleId] = (c[m.ruleId] || 0) + 1;
console.log(c);
대응
- 켜고 싶은 룰을 직접 나열합니다. 프리셋으로 딸려 들어온
error묶음을 그대로 두면 다음 업데이트에서 같은 일이 반복됩니다. - 가능하면
FlatCompat을 걷어내고 shareable config의 flat 진입점을 직접 씁니다. 그러면 config가 의도한 플러그인 버전이 적용되고, 해석 위치 문제 자체가 사라집니다. - lint 플러그인 업데이트를 "dev 의존성이니 안전"으로 분류하지 않습니다. 최소한 lint를 CI에 넣어 이런 회귀를 PR에서 잡습니다.
정리
FlatCompat은 호환 레이어이지 같은 동작을 보장하지 않습니다. legacy extends, plugins, parser에 문자열로 적힌 이름은 config 주인이 아니라 읽는 쪽 기준으로 해석됩니다. 패키지가 플러그인 버전을 고정해 뒀다고 그 버전이 쓰인다는 보장은 없고, 어느 진입점을 타는지가 결정합니다.