Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added the require-mock-type-parameters rule #651

Merged
merged 6 commits into from
Feb 8, 2025

Conversation

marekdedic
Copy link
Contributor

@marekdedic marekdedic commented Feb 4, 2025

So far the rule is only implemented for vi.fn(). I'd also like to implement it for other functions, specifically these are the ones which have a generic type argument that is not present in the function parameters and so won't be automatically inferred:

  • vi.importActual
  • vi.importMock

but these two I think should be behind a configuration flag, because I can imagine people not wanting to bother with them. What do you think? Anyway, I wanted to get some feedback (@veritem) on the design before proceeding.

I think this rule should also be turned off for files that aren't TypeScript, so you have any infrastructure set up for this?

Thanks for your feedback.

Closes #649

@veritem
Copy link
Member

veritem commented Feb 7, 2025

but these two I think should be behind a configuration flag, because I can imagine people not wanting to bother with them. What do you think? Anyway, I wanted to get some feedback (@veritem) on the design before proceeding.

@marekdedic I agree, let's make them optional unless the user explicitly enables them using configuration files.

I think this rule should also be turned off for files that aren't TypeScript, so do you have any infrastructure set up for this?

I don't have specific ways to turn off rules for typescript files. But there is a configuration setting to enable typescript's type checker -- refer to this section on how we handle it

const settings = parsePluginSettings(context.settings)

@marekdedic marekdedic force-pushed the require-mock-type-parameters branch from 45dcc2b to e054b87 Compare February 8, 2025 13:03
@marekdedic
Copy link
Contributor Author

Hi,
great, I added support for importActual and importMock behind a configuration option. The thing you linked is for type checking, which is not the case here - the rule works perfectly fine without typechecking, it just doesn't make sense without typescript at all. But if you don't really check that elsewhere, we can just leave it as is and leave it to users to turn this rule off where they want to...

@marekdedic marekdedic marked this pull request as ready for review February 8, 2025 14:12
@veritem veritem merged commit 5674c25 into vitest-dev:main Feb 8, 2025
@marekdedic marekdedic deleted the require-mock-type-parameters branch February 9, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rule requiring type parameters
2 participants