Skip to content

Conversation

@azat-io
Copy link
Contributor

@azat-io azat-io commented Jun 24, 2025

Fix false positives in prefer-importing-vitest-globals rule.

The prefer-importing-vitest-globals rule was incorrectly flagging local variables, function parameters, and other local bindings that happened to have the same name as vitest globals (like test, describe, it, etc.).

For example, this code would incorrectly trigger the rule:

import { describe, expect, it } from 'vitest'

describe('test suite', () => {
  it('should work', () => {
    let test = createTestWithParameters(3) // Rule incorrectly flagged this
    expect(test()).toBeTruthy()
  })
})

I encountered an issue in my project:
https://github.com/azat-io/eslint-plugin-de-morgan/blob/main/test/utils/create-test-with-parameters.test.ts

Added proper scope analysis to distinguish between:

  • Local bindings (variables, parameters, function declarations) - should be ignored
  • Import bindings from non-vitest modules - should be flagged
  • Actual vitest global function calls - should be flagged if not imported

The rule now correctly identifies when an identifier refers to a local binding rather than a missing vitest global import.

Copy link
Member

@veritem veritem left a comment

Choose a reason for hiding this comment

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

thank you!

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.

2 participants