Skip to content

Handle braceless core.setFailed() control-flow in require-return-after-core-setfailed#45430

Merged
pelikhan merged 2 commits into
mainfrom
copilot/eslint-factory-fix-return-checks
Jul 14, 2026
Merged

Handle braceless core.setFailed() control-flow in require-return-after-core-setfailed#45430
pelikhan merged 2 commits into
mainfrom
copilot/eslint-factory-fix-return-checks

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

require-return-after-core-setfailed was missing direct single-statement control bodies, so braceless if/else branches and loop bodies could call core.setFailed() and still fall through without being diagnosed. The gap was positional: the braced form was reported, while the equivalent braceless form was not.

  • Expand continuation analysis

    • Analyze core.setFailed() when it is the direct braceless body of:
      • if / else
      • while
      • do...while
      • for
      • for...in
      • for...of
    • Reuse the existing continuation search so these forms are treated consistently with braced blocks and existing loop back-edge handling.
  • Keep fixer output syntactically correct

    • When the reported setFailed() is a direct braceless control body, the addReturn suggestion now wraps it in a block before inserting return;.
    • This preserves control-flow association and avoids detached fixes like:
      if (bad) core.setFailed("x"); return;
  • Add focused regression coverage

    • Invalid cases for braceless:
      • if with following continuation
      • if/else with following continuation
      • loop bodies with continuation
      • recognized callee variants (core.setFailed, core["setFailed"], alias, destructured binding)
    • Valid case for terminal braceless if with no continuation.

Example:

function f() {
  if (bad) core.setFailed("x");
  doMore();
}

Suggested fix:

function f() {
  if (bad) { core.setFailed("x"); return; }
  doMore();
}

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix require-return-after-core-setfailed for unbraced statements Handle braceless core.setFailed() control-flow in require-return-after-core-setfailed Jul 14, 2026
Copilot AI requested a review from pelikhan July 14, 2026 10:36
@pelikhan pelikhan marked this pull request as ready for review July 14, 2026 10:59
Copilot AI review requested due to automatic review settings July 14, 2026 10:59
@pelikhan pelikhan merged commit 9a8023f into main Jul 14, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/eslint-factory-fix-return-checks branch July 14, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends the ESLint rule to detect fall-through after braceless core.setFailed() control bodies and provide block-wrapping fixes.

Changes:

  • Adds direct if and loop-body analysis.
  • Adds fixer handling and regression tests for braceless bodies.
Show a summary per file
File Description
require-return-after-core-setfailed.ts Adds detection and suggestions for braceless control bodies.
require-return-after-core-setfailed.test.ts Adds braceless control-flow regression cases.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Medium

fix(fixer) {
const directControlBodyContainer = getDirectControlBodyContainer(node);
if (directControlBodyContainer !== null) {
return fixer.replaceText(node, `{ ${sourceCode.getText(node)} return; }`);
Comment on lines +384 to +385
DoWhileStatement(node: TSESTree.DoWhileStatement) {
checkDirectControlBody(node.body);
Comment on lines +355 to +356
if (continuation !== null && !isControlTransfer(continuation)) {
reportNested(stmt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

eslint-factory: require-return-after-core-setfailed misses braceless if/else/loop consequents (control-flow FN)

3 participants