Skip to content

fix(linter/prefer-mock-return-shorthand): avoid unsafe autofixes for call-like returns#19581

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/02-20-fix_jest_avoid_unsafe_prefer-mock-return-shorthand_autofixes_for_call-like_returns
Feb 21, 2026
Merged

fix(linter/prefer-mock-return-shorthand): avoid unsafe autofixes for call-like returns#19581
graphite-app[bot] merged 1 commit intomainfrom
c/02-20-fix_jest_avoid_unsafe_prefer-mock-return-shorthand_autofixes_for_call-like_returns

Conversation

@camc314
Copy link
Contributor

@camc314 camc314 commented Feb 20, 2026

fixes #19580

Copy link
Contributor Author

camc314 commented Feb 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Feb 20, 2026
@camc314 camc314 marked this pull request as ready for review February 20, 2026 16:17
Copilot AI review requested due to automatic review settings February 20, 2026 16:17
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 20, 2026

Merging this PR will not alter performance

✅ 47 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing c/02-20-fix_jest_avoid_unsafe_prefer-mock-return-shorthand_autofixes_for_call-like_returns (3342467) with main (50fc70d)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue in the jest/prefer-mock-return-shorthand linting rule where unsafe autofixes were being suggested for mock implementations that return call-like expressions (function calls, new expressions, etc.). The fix ensures the diagnostic is still reported but prevents the autofix from being applied in these cases, since autofixing would change the code's behavior.

Changes:

  • Added detection for call-like expressions (calls, new expressions, tagged templates, import expressions) in mock return values
  • Changed parameter checking from is_empty() to has_parameter() to properly handle rest parameters
  • Updated test cases to reflect the new behavior: cases with calls are flagged but not autofixed

Reviewed changes

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

File Description
crates/oxc_linter/src/rules/jest/prefer_mock_return_shorthand.rs Implemented CallLikeExpressionVisitor to detect call-like expressions; modified main rule logic to skip autofix when calls are detected; fixed parameter checking to handle rest parameters
crates/oxc_linter/src/snapshots/jest_prefer_mock_return_shorthand.snap Updated snapshots to include diagnostics for call-like return expressions that now report issues without autofixes

@camc314 camc314 changed the title fix(jest): avoid unsafe prefer-mock-return-shorthand autofixes for call-like returns fix(linter/prefer-mock-return-shorthand): avoid unsafe autofixes for call-like returns Feb 20, 2026
@camc314 camc314 self-assigned this Feb 21, 2026
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Feb 21, 2026
Copy link
Contributor Author

camc314 commented Feb 21, 2026

Merge activity

@graphite-app graphite-app bot force-pushed the c/02-20-fix_jest_avoid_unsafe_prefer-mock-return-shorthand_autofixes_for_call-like_returns branch from 3342467 to 79fe3b4 Compare February 21, 2026 13:04
@graphite-app graphite-app bot merged commit 79fe3b4 into main Feb 21, 2026
21 checks passed
@graphite-app graphite-app bot deleted the c/02-20-fix_jest_avoid_unsafe_prefer-mock-return-shorthand_autofixes_for_call-like_returns branch February 21, 2026 13:10
camc314 pushed a commit that referenced this pull request Feb 23, 2026
# Oxlint
### 🚀 Features

- 46177dd linter: Implement unicorn/prefer-module (#19603) (camc314)
- 42f78bb linter: Implement unicorn/prefer-ternary (#19605) (camc314)

### 🐛 Bug Fixes

- 43df857 react/exhaustive-deps: Normalize .current callback deps
(#19610) (camc314)
- 574f48f linter/no-throw-literal: Close warning block (#19612)
(camc314)
- 79fe3b4 linter/prefer-mock-return-shorthand: Avoid unsafe autofixes
for call-like returns (#19581) (camc314)
- 85045e8 linter: Check protected members in
explicit-module-boundary-types (#19594) (camc314)
- e38115e linter: Catch missing return type on exported arrow/function
expressions (#19587) (Peter Wagenet)
- 419d3fd linter: Fix false negatives in typescript/no-require-imports
(#19589) (Peter Wagenet)
- 7958b56 linter: Fix syntax error reporting in some output formatters.
(#19590) (connorshea)
- 024f51c linter: Add help text to more eslint diagnostics (#19591)
(Anthony Amaro)
- a8489a1 linter: Warning `eslint/no-throw-literal` rule to be
deprecated, better use `typescript/only-throw-error` (#19593) (Said
Atrahouch)
- 50fc70d linter/type-aware: Use correct span for disable directives
(#19576) (camc314)
- 421a99c linter: Add help guidance to eslint diagnostic messages
(#19562) (Anthony Amaro)
- e81364a linter: Add help text to eslint rule diagnostics (#19560)
(Anthony Amaro)
- 89b58d0 linter: Add help text to more eslint rule diagnostics (#19561)
(Anthony Amaro)
- 74f7833 linter/jest/prefer-mock-return-shorthand: Preserve typed arrow
returns (#19556) (camc314)
- bdd6f34 linter: Restrict prefer-import-in-mock to mock calls (#19555)
(camc314)

### 📚 Documentation

- a331993 linter: Improve docs for `eslint/radix` rule. (#19611)
(connorshea)

### 🛡️ Security

- c67f9dc linter: Update ajv version. (#19613) (connorshea)
# Oxfmt
### 🚀 Features

- 984dc07 oxfmt: Strip `"experimental"SortXxx` prefix (#19567)
(leaysgur)

### 🐛 Bug Fixes

- d7b63a4 oxfmt: Update API types for `sortPackageJsonOptions` (#19569)
(leaysgur)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0-merge Merge with Graphite Merge Queue A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: jest/prefer-mock-return-shorthand disregards function calls

2 participants