Skip to content

Conversation

@Afsoon
Copy link
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

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
Contributor

@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
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
Contributor

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
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
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
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
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
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]>
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