feat(linter/eslint-plugin-vitest): reuse no-mocks-import jest linter rule#16540
feat(linter/eslint-plugin-vitest): reuse no-mocks-import jest linter rule#16540camc314 merged 4 commits intooxc-project:mainfrom
Conversation
CodSpeed Performance ReportMerging #16540 will not alter performanceComparing Summary
Footnotes
|
connorshea
left a comment
There was a problem hiding this comment.
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"
/// }
/// }
/// ```
daea57d to
3ad66ee
Compare
|
@connorshea Added missing dock blocks and update the PR description to point the
Just FYI, some compatibles vitest rule are missing that doc block, for example |
Good point, if you want to open a PR for that change, I'd be happy to review/merge that :) |
3ad66ee to
ff3ba37
Compare
PR created #16679 |
camc314
left a comment
There was a problem hiding this comment.
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.
oxc/crates/oxc_linter/src/rules/jest/consistent_test_it.rs
Lines 794 to 795 in 4911d60
…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
ff3ba37 to
51019f0
Compare
|
@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:
|
|
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 |
… and message based on framework
da395e9 to
9734366
Compare
stale - comment has been updated
…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
…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]>
…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
…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]>
…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.
…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.
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