Skip to content

Commit a99d8e8

Browse files
authored
[compiler][eslint] Report bailout diagnostics with correct column # (#30977)
Compiler bailout diagnostics should now highlight only the first line of the source location span. (Resubmission of #30423 which was reverted due to invalid column number.)
1 parent 8152e5c commit a99d8e8

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

compiler/packages/eslint-plugin-react-compiler/src/rules/ReactCompilerRule.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,33 @@ const rule: Rule.RuleModule = {
166166
detail.loc != null && typeof detail.loc !== 'symbol'
167167
? ` (@:${detail.loc.start.line}:${detail.loc.start.column})`
168168
: '';
169+
/**
170+
* Report bailouts with a smaller span (just the first line).
171+
* Compiler bailout lints only serve to flag that a react function
172+
* has not been optimized by the compiler for codebases which depend
173+
* on compiler memo heavily for perf. These lints are also often not
174+
* actionable.
175+
*/
176+
let endLoc;
177+
if (event.fnLoc.end.line === event.fnLoc.start.line) {
178+
endLoc = event.fnLoc.end;
179+
} else {
180+
endLoc = {
181+
line: event.fnLoc.start.line,
182+
// Babel loc line numbers are 1-indexed
183+
column: sourceCode.split(
184+
/\r?\n|\r|\n/g,
185+
event.fnLoc.start.line,
186+
)[event.fnLoc.start.line - 1].length,
187+
};
188+
}
189+
const firstLineLoc = {
190+
start: event.fnLoc.start,
191+
end: endLoc,
192+
};
169193
context.report({
170194
message: `[ReactCompilerBailout] ${detail.reason}${locStr}`,
171-
loc: event.fnLoc,
195+
loc: firstLineLoc,
172196
suggest,
173197
});
174198
}

0 commit comments

Comments
 (0)