Skip to content

feat(linter/eslint-plugin-vitest): reuse no-mocks-import jest linter rule#16540

Merged
camc314 merged 4 commits intooxc-project:mainfrom
Afsoon:12-05-vitest_no_mocks_import
Dec 10, 2025
Merged

feat(linter/eslint-plugin-vitest): reuse no-mocks-import jest linter rule#16540
camc314 merged 4 commits intooxc-project:mainfrom
Afsoon:12-05-vitest_no_mocks_import

Conversation

@Afsoon
Copy link
Copy Markdown
Contributor

@Afsoon Afsoon commented Dec 5, 2025

Related to #4656

Implement no-mocks-import lint ruler adding a new entry in the mapping between jest and vitest compatible rules.

Oxlint-migrate PR related: oxc-project/oxlint-migrate#269

@Afsoon Afsoon requested a review from camc314 as a code owner December 5, 2025 12:28
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 5, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 5, 2025

CodSpeed Performance Report

Merging #16540 will not alter performance

Comparing Afsoon:12-05-vitest_no_mocks_import (9734366) with main (f1581c1)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (90c950f) during the generation of this report, so f1581c1 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 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.

Copy link
Copy Markdown
Member

@connorshea connorshea left a comment

Choose a reason for hiding this comment

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

The docs block in the declare_oxc_lint! should be updated to mention that this rule is compatible with Vitest as well. (we should probably consider auto-generating something in the docs for these cases as well, honestly, but for now this is how it is done).

Other rules have a note like so:

    /// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/v1.1.9/docs/rules/no-alias-methods.md),
    /// to use it, add the following configuration to your `.oxlintrc.json`:
    ///
    /// ```json
    /// {
    ///   "rules": {
    ///      "vitest/no-alias-methods": "error"
    ///   }
    /// }
    /// ```

@Afsoon Afsoon changed the title feat(linter/eslint-plugin-vitest): reuse the jest linter rule feat(linter/eslint-plugin-vitest): reuse no-mocks-import jest linter rule Dec 7, 2025
@Afsoon Afsoon force-pushed the 12-05-vitest_no_mocks_import branch from daea57d to 3ad66ee Compare December 7, 2025 07:35
@Afsoon
Copy link
Copy Markdown
Contributor Author

Afsoon commented Dec 7, 2025

@connorshea Added missing dock blocks and update the PR description to point the oxlint-migrate PR. I haven't opened before because I didn't know when to open it.

The docs block in the declare_oxc_lint! should be updated to mention that this rule is compatible with Vitest as well. (we should probably consider auto-generating something in the docs for these cases as well, honestly, but for now this is how it is done).

Other rules have a note like so:

    /// This rule is compatible with [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest/blob/v1.1.9/docs/rules/no-alias-methods.md),
    /// to use it, add the following configuration to your `.oxlintrc.json`:
    ///
    /// ```json
    /// {
    ///   "rules": {
    ///      "vitest/no-alias-methods": "error"
    ///   }
    /// }
    /// ```

Just FYI, some compatibles vitest rule are missing that doc block, for example jest/prefer_each. It's out of scope of this PR, but maybe can be a good idea to review which compatible rules don't have this dock block.

@connorshea
Copy link
Copy Markdown
Member

Just FYI, some compatibles vitest rule are missing that doc block, for example jest/prefer_each. It's out of scope of this PR, but maybe can be a good idea to review which compatible rules don't have this dock block.

Good point, if you want to open a PR for that change, I'd be happy to review/merge that :)

@Afsoon
Copy link
Copy Markdown
Contributor Author

Afsoon commented Dec 10, 2025

Just FYI, some compatibles vitest rule are missing that doc block, for example jest/prefer_each. It's out of scope of this PR, but maybe can be a good idea to review which compatible rules don't have this dock block.

Good point, if you want to open a PR for that change, I'd be happy to review/merge that :)

PR created #16679

@camc314 camc314 self-assigned this Dec 10, 2025
Copy link
Copy Markdown
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.

Thanks for working on this!

Do you mind also porting the vitest test cases for this rule to ensure that we're catching all cases?

This can be done by:

just new-vitest-rule no-mocks-import

And copying over the generated test cases to crates/oxc_linter/src/rules/jest/no_mocks_import.rs, this allows us to ensure that we're reporting all cases correctly for both vitest/jest

e.g.

let fail_vitest = vec![

camc314 pushed a commit that referenced this pull request Dec 10, 2025
…h vitest. (#16679)

After the review @connorshea did in
#16540 (review),
suggested to me add a missing part of documentation in the linter rule.
I hadn't added it because the reference rule I used lack of it.

So this PR aims to add it in all jest rules stated as compatible.

## Before this PR

The following Jest linter only had this documentation part:

- consistent-test-it
- expect-expect
- no-alias-methods
- no-commented-out-tests
- no-disabled-tests
- no-focused-tests
- no-identical-title
- no-test-prefixes
- prefer-hooks-in-order
- valid-describe-callback
- valid-expect

## Adding in this PR

- max-expects
- max-nested-describe
- no-conditional-expect
- no-conditional-in-test
- no-duplicate-hooks
- no-hooks
- no-interpolation-in-snapshots
- no-restricted-jest-methods: I have doubts here see my comment in the
[vitest-eslint-plugin
issue](#4656 (comment))
- no-restricted-matchers
- no-standalone-expect
- no-test-return-statement
- prefer-comparison-matcher
- prefer-each
- prefer-equality-matcher
- prefer-expect-resolves
- prefer-hooks-on-top
- prefer-lowercase-title
- prefer-mock-promise-shorthand
- prefer-strict-equal
- prefer-to-be
- prefer-to-have-length
- prefer-todo
- require-to-throw-message
- require-top-level-describe
@Afsoon Afsoon force-pushed the 12-05-vitest_no_mocks_import branch from ff3ba37 to 51019f0 Compare December 10, 2025 13:59
@Afsoon
Copy link
Copy Markdown
Contributor Author

Afsoon commented Dec 10, 2025

@camc314 Updated the PR with the vitests test case but I have notice the diagnostic message is framework dependant. I'm not sure how to approach here:

  • The current approach
  • One diagnostic method but add a new argument, for example:
let caller = {
  if ctx.frameworks().is_vitest() {
      "vi"
  }

 "jest"
};

fn no_mocks_import_diagnostic(span: Span, call: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn("Mocks should not be manually imported from a `__mocks__` directory.")
        .with_help(format!("Instead use `{call}.mock` and import from the original module path."))
        .with_label(span)
}
  • Duplicate the rule under the vitest folder.

Copy link
Copy Markdown
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.

Thank yoiu!

@camc314
Copy link
Copy Markdown
Contributor

camc314 commented Dec 10, 2025

I pushed another commit - it just merges the two diagnostic messages together. It's tricky to know if we are in a vitest/jest file, so for simplicity, we just report the same error

Afsoon and others added 4 commits December 10, 2025 14:10
u
framwork flags can sometime be unreliable, so merge the two help messages into one, and update the help text
@camc314 camc314 force-pushed the 12-05-vitest_no_mocks_import branch from da395e9 to 9734366 Compare December 10, 2025 14:10
@camc314 camc314 dismissed connorshea’s stale review December 10, 2025 14:13

stale - comment has been updated

@camc314 camc314 merged commit a1d9bbd into oxc-project:main Dec 10, 2025
19 checks passed
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
…h vitest. (#16679)

After the review @connorshea did in
#16540 (review),
suggested to me add a missing part of documentation in the linter rule.
I hadn't added it because the reference rule I used lack of it.

So this PR aims to add it in all jest rules stated as compatible.

## Before this PR

The following Jest linter only had this documentation part:

- consistent-test-it
- expect-expect
- no-alias-methods
- no-commented-out-tests
- no-disabled-tests
- no-focused-tests
- no-identical-title
- no-test-prefixes
- prefer-hooks-in-order
- valid-describe-callback
- valid-expect

## Adding in this PR

- max-expects
- max-nested-describe
- no-conditional-expect
- no-conditional-in-test
- no-duplicate-hooks
- no-hooks
- no-interpolation-in-snapshots
- no-restricted-jest-methods: I have doubts here see my comment in the
[vitest-eslint-plugin
issue](#4656 (comment))
- no-restricted-matchers
- no-standalone-expect
- no-test-return-statement
- prefer-comparison-matcher
- prefer-each
- prefer-equality-matcher
- prefer-expect-resolves
- prefer-hooks-on-top
- prefer-lowercase-title
- prefer-mock-promise-shorthand
- prefer-strict-equal
- prefer-to-be
- prefer-to-have-length
- prefer-todo
- require-to-throw-message
- require-top-level-describe
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
…rule (#16540)

Related to #4656

Implement
[no-mocks-import](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-mocks-import.md)
lint ruler adding a new entry in the mapping between jest and vitest
compatible rules.

Oxlint-migrate PR related:
oxc-project/oxlint-migrate#269

---------

Co-authored-by: Cameron Clark <[email protected]>
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…h vitest. (oxc-project#16679)

After the review @connorshea did in
oxc-project#16540 (review),
suggested to me add a missing part of documentation in the linter rule.
I hadn't added it because the reference rule I used lack of it.

So this PR aims to add it in all jest rules stated as compatible.

## Before this PR

The following Jest linter only had this documentation part:

- consistent-test-it
- expect-expect
- no-alias-methods
- no-commented-out-tests
- no-disabled-tests
- no-focused-tests
- no-identical-title
- no-test-prefixes
- prefer-hooks-in-order
- valid-describe-callback
- valid-expect

## Adding in this PR

- max-expects
- max-nested-describe
- no-conditional-expect
- no-conditional-in-test
- no-duplicate-hooks
- no-hooks
- no-interpolation-in-snapshots
- no-restricted-jest-methods: I have doubts here see my comment in the
[vitest-eslint-plugin
issue](oxc-project#4656 (comment))
- no-restricted-matchers
- no-standalone-expect
- no-test-return-statement
- prefer-comparison-matcher
- prefer-each
- prefer-equality-matcher
- prefer-expect-resolves
- prefer-hooks-on-top
- prefer-lowercase-title
- prefer-mock-promise-shorthand
- prefer-strict-equal
- prefer-to-be
- prefer-to-have-length
- prefer-todo
- require-to-throw-message
- require-top-level-describe
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…rule (oxc-project#16540)

Related to oxc-project#4656

Implement
[no-mocks-import](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/no-mocks-import.md)
lint ruler adding a new entry in the mapping between jest and vitest
compatible rules.

Oxlint-migrate PR related:
oxc-project/oxlint-migrate#269

---------

Co-authored-by: Cameron Clark <[email protected]>
graphite-app bot pushed a commit that referenced this pull request Dec 17, 2025
…ented (#16940)

The vitest rule `no-restricted-vi-methods` is implemented via the jest rule `no-restricted-jest-methods`, but the different names prevented automatic status syncing in the rules table generation.

## Changes

- **tasks/lint_rules/src/oxlint-rules.mjs**: Added special case in `syncVitestPluginStatusWithJestPluginStatus()` to map `vitest/no-restricted-vi-methods` status from `jest/no-restricted-jest-methods`

## Result

The rules table will correctly show `vitest/no-restricted-vi-methods` as implemented when the lint rules tracking task is run.

<!-- START COPILOT ORIGINAL PROMPT -->

<details>

<summary>Original prompt</summary>

>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>linter: rules table does not properly mark no-restricted-vi-methods as implemented</issue_title>
> <issue_description>> Working in #16540 I have notice that `vitest/no-restricted-vi-methods` is implemented but the table show as not. As you can see
> >
> > https://github.com/oxc-project/oxc/blob/d6d2bcd1c7b2524addab2394c2849ba809006567/crates/oxc_linter/src/utils/mod.rs#L51
> >
> > Probably is due a name mistmatch. For Vitest the linter is named `no-restricted-vi-methods` but in jest is `no-restricted-jest-methods`. Following you can see how the jest rule have test case for the vitest context:
> >
> > https://github.com/oxc-project/oxc/blob/d6d2bcd1c7b2524addab2394c2849ba809006567/crates/oxc_linter/src/rules/jest/no_restricted_jest_methods.rs#L198-L231
>
>  _Originally posted by @Afsoon in [#4656](#4656 (comment)
>
> We should fix this by adding a one-off logic change to the rule list generation logic when mapping jest<->vitest rules, probably?</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>

</details>

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #16732

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
qinyuhang pushed a commit to qinyuhang/oxc that referenced this pull request Jan 22, 2026
…ented (oxc-project#16940)

The vitest rule `no-restricted-vi-methods` is implemented via the jest rule `no-restricted-jest-methods`, but the different names prevented automatic status syncing in the rules table generation.

## Changes

- **tasks/lint_rules/src/oxlint-rules.mjs**: Added special case in `syncVitestPluginStatusWithJestPluginStatus()` to map `vitest/no-restricted-vi-methods` status from `jest/no-restricted-jest-methods`

## Result

The rules table will correctly show `vitest/no-restricted-vi-methods` as implemented when the lint rules tracking task is run.

<!-- START COPILOT ORIGINAL PROMPT -->

<details>

<summary>Original prompt</summary>

>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>linter: rules table does not properly mark no-restricted-vi-methods as implemented</issue_title>
> <issue_description>> Working in oxc-project#16540 I have notice that `vitest/no-restricted-vi-methods` is implemented but the table show as not. As you can see
> >
> > https://github.com/oxc-project/oxc/blob/d6d2bcd1c7b2524addab2394c2849ba809006567/crates/oxc_linter/src/utils/mod.rs#L51
> >
> > Probably is due a name mistmatch. For Vitest the linter is named `no-restricted-vi-methods` but in jest is `no-restricted-jest-methods`. Following you can see how the jest rule have test case for the vitest context:
> >
> > https://github.com/oxc-project/oxc/blob/d6d2bcd1c7b2524addab2394c2849ba809006567/crates/oxc_linter/src/rules/jest/no_restricted_jest_methods.rs#L198-L231
>
>  _Originally posted by @Afsoon in [oxc-project#4656](oxc-project#4656 (comment)
>
> We should fix this by adding a one-off logic change to the rule list generation logic when mapping jest<->vitest rules, probably?</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>

</details>

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes oxc-project#16732

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.
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.

3 participants