Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 28, 2025

The catch-or-return rule incorrectly flagged arrow functions with implicit returns as missing catch handlers, even though implicit returns are semantically equivalent to explicit returns.

// Was incorrectly flagged as needing .catch()
const handler = () => Promise.resolve(null);

// Also incorrectly flagged
const obj = {
  method: () => Promise.resolve({ id: '' })
};

Changes

  • Added is_in_returned_context helper: Detects when an ExpressionStatement is the body of an arrow function with expression = true, indicating an implicit return
  • Updated rule logic: Skip diagnostic for promises in implicitly-returned contexts
  • Added test coverage: 10 new test cases covering arrow functions with implicit returns, block bodies, and edge cases
  • Updated documentation: Added arrow function example to rule description

Technical Details

Arrow functions with expression bodies (() => expr) set expression = true on the AST node. The body still contains a FunctionBody with an ExpressionStatement, but the expression flag indicates it's implicitly returned. The fix walks the AST parent chain to detect this pattern.

Original prompt

This section details on the original issue you should resolve

<issue_title>linter: catch-or-return doesn't handle inline arrow functions</issue_title>
<issue_description>The eslint-plugin-promise(catch-or-return) isn't properly detecting a return with inline arrow functions.

This is the error that its reporting, however looking at the snippet, the error is invalid since the promise is being returned.

I'm using 1.35.0

  × eslint-plugin-promise(catch-or-return): Expected `catch` or `return`.
    ╭─[src/areas/project-management/modals/template-task-modal/template-task-form-handlers.tsx:42:30]
 41 │   uploadImage: () => Promise.resolve(undefined),
 42 │   openLinkModalPrompt: () => Promise.resolve(null),
    ·                              ─────────────────────
 43 │   submitTemplate: () => Promise.resolve({ id: '' }),
    ╰────
  help: Return the promise or chain a `catch()`.
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix linter catch-or-return for inline arrow functions fix(linter): catch-or-return handles arrow functions with implicit returns Dec 28, 2025
Copilot AI requested a review from camc314 December 28, 2025 21:00
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.

linter: catch-or-return doesn't handle inline arrow functions

2 participants