Skip to content

feat(linter): implement vitest/prefer-called-times#17051

Merged
camc314 merged 6 commits intooxc-project:mainfrom
qinyuhang:oxc_dev
Dec 20, 2025
Merged

feat(linter): implement vitest/prefer-called-times#17051
camc314 merged 6 commits intooxc-project:mainfrom
qinyuhang:oxc_dev

Conversation

@qinyuhang
Copy link
Contributor

Ref: #4656

This PR implements vitest/prefer-called-times rule.

Test Plan

  • All fail cases pass
  • All pass cases pass
  • All expect fix get fix suggestions
  • No clippy warnings
  • Code formatted with just fmt

@qinyuhang qinyuhang requested a review from camc314 as a code owner December 18, 2025 10:58
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 18, 2025
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

@camc314 camc314 self-assigned this Dec 18, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 18, 2025

CodSpeed Performance Report

Merging #17051 will not alter performance

Comparing qinyuhang:oxc_dev (d2bfbf5) with main (30fb206)

Summary

✅ 4 untouched
⏩ 41 skipped1

Footnotes

  1. 41 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.

@qinyuhang
Copy link
Contributor Author

This looks to be the same as https://github.com/Boshen/oxc/blob/fc96ee09189a3510078dd0d072a424affdb6dbc4/crates/oxc_linter/src/rules/jest/prefer_to_have_been_called_times.rs#L1, can we take the same approach as 477bb57 / #4956

Yes, the two PRs share some code path. I think we could somehow extract the common functions.

@qinyuhang
Copy link
Contributor Author

This looks to be the same as https://github.com/Boshen/oxc/blob/fc96ee09189a3510078dd0d072a424affdb6dbc4/crates/oxc_linter/src/rules/jest/prefer_to_have_been_called_times.rs#L1, can we take the same approach as 477bb57 / #4956

Though the two implements share some common pattern and code path. I'm concerned about they actually check different syntax. Is it appropriate to mix them together?

jest/prefer-to-have-been-called-times checks expect(someVar.mock.calls).toHaveLength(someLength) and provider fix to expect(someVar.mock.calls).toHaveBeenCalled(someLength)

while vitest/prefer-called-times checks expect(someFunction).toBeCalledOnce() and provider fix to expect(someFunction).toBeCalled(1)

@camc314
Copy link
Contributor

camc314 commented Dec 19, 2025

Ah thanks for checking, we can keep them separate

@camc314 camc314 merged commit 16d9dc2 into oxc-project:main Dec 20, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants