Skip to content

Fix jsx-no-leaked-render autofix for expression alternates#4017

Open
morgan-coded wants to merge 1 commit into
jsx-eslint:masterfrom
morgan-coded:fix/3927-jsx-no-leaked-render-autofix
Open

Fix jsx-no-leaked-render autofix for expression alternates#4017
morgan-coded wants to merge 1 commit into
jsx-eslint:masterfrom
morgan-coded:fix/3927-jsx-no-leaked-render-autofix

Conversation

@morgan-coded

Copy link
Copy Markdown

Problem I saw:
jsx-no-leaked-render could produce a destructive autofix for JSX attribute ternaries when validStrategies: ["coerce"] was used.
The old alternate check read .value from expression nodes that do not have one, so JSX, call, or nested conditional alternates could fall through as undefined and get removed from the fix.
What I changed:
I replaced that broad .value check with explicit checks for the alternates that should be treated as leaked values.
The rule still reports : null, : false, : undefined, and : void 0 in coerce-only mode, and it keeps the existing condition ? false : value conversion. The autofix now preserves expression alternates such as JSX, calls, nested conditionals, and logical || expressions.
How I checked it:
I confirmed the targeted rule test failed before the fix with 186 passing and 3 failing.
After the fix, the focused jsx-no-leaked-render suite passed with 216 tests. The full unit suite passed with 17,899 tests, changed-file ESLint passed, and git diff --check was clean.
Closes #3927

Copilot AI review requested due to automatic review settings June 7, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds safer handling for ternary alternates under the coerce strategy in jsx-no-leaked-render, ensuring alternates like undefined/void 0 are caught while preserving side effects and valid ternary branches during autofix.

Changes:

  • Expand ternary alternate detection to treat undefined identifiers and void 0 as invalid alternates.
  • Improve coerce fixer output by parenthesizing alternates that need precedence protection.
  • Add regression tests covering nested ternaries, void sideEffect(), and undefined/void 0 alternates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/lib/rules/jsx-no-leaked-render.js Adds regression tests for ternary alternates and coerce-strategy autofix behavior.
lib/rules/jsx-no-leaked-render.js Updates detection logic for invalid ternary alternates and refines fixer output formatting/parenthesization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/rules/jsx-no-leaked-render.js Outdated
Comment on lines +32 to +40
function isInvalidTernaryAlternate(node) {
if (node.type === 'Identifier') {
return node.name === 'undefined';
}
if (node.type === 'UnaryExpression') {
return node.operator === 'void' && node.argument.type === 'Literal';
}
return node.type === 'Literal' && TERNARY_INVALID_ALTERNATE_VALUES.indexOf(node.value) > -1;
}
Comment thread lib/rules/jsx-no-leaked-render.js Outdated
if (node.type === 'UnaryExpression') {
return node.operator === 'void' && node.argument.type === 'Literal';
}
return node.type === 'Literal' && TERNARY_INVALID_ALTERNATE_VALUES.indexOf(node.value) > -1;
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.59%. Comparing base (c9a2de7) to head (a0dc6b9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4017      +/-   ##
==========================================
- Coverage   97.71%   97.59%   -0.13%     
==========================================
  Files         137      137              
  Lines       10188    10208      +20     
  Branches     3797     3808      +11     
==========================================
+ Hits         9955     9962       +7     
- Misses        233      246      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@morgan-coded morgan-coded force-pushed the fix/3927-jsx-no-leaked-render-autofix branch from 261952c to a0dc6b9 Compare June 7, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: react/jsx-no-leaked-render coerce setting removing ternaries entirely when autofixing

2 participants