Skip to content
New issue

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

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

Already on GitHub? # to your account

Rule: Disallow global imports #486

Open
Undistraction opened this issue Aug 2, 2024 · 5 comments
Open

Rule: Disallow global imports #486

Undistraction opened this issue Aug 2, 2024 · 5 comments
Labels
good first issue Good for newcomers

Comments

@Undistraction
Copy link

Undistraction commented Aug 2, 2024

By default eslint will flag vitest globals that aren't imported (describe , expect) etc as errors because they violate the no-undef rule:

error 'describe' is not defined no-undef

We can prevent this using :

env: {
  'vitest/env': true`
}

Or for flat file config:

languageOptions: {
      globals: {
        ...vitest.environments.env.globals,
      },
    }

So there are effectively two styles: one where globals are manually imported per test file, and one where they are not. It would make sense to have a rule that covered the latter style and detected imports of globals from 'vitest' in test files.

@veritem
Copy link
Member

veritem commented Aug 2, 2024

A PR is welcome

@Undistraction
Copy link
Author

@veritem I'll get that done this week.

@Undistraction
Copy link
Author

@veritem looking at jest-eslint they have a rule for one side of this: prefer-importing-jest-globals, but not the other, meaning they have a rule to enforce the presence of jest globals, but not one to enforce their absence. Would you be happy with two different rules:

  • prefer-importing-vitest-globals
  • no-importing-vitest-globals

@veritem
Copy link
Member

veritem commented Aug 5, 2024

Let's have both rules for flexibility.

@veritem
Copy link
Member

veritem commented Dec 26, 2024

@Undistraction were you able to make a progress on this one?

@veritem veritem added the good first issue Good for newcomers label Dec 26, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants