vitest/consistent-vitest-vi
Enforce one of vi or vitest for Vitest's helper object
fixable
Vitest exports its helper object under two names, vi and vitest. They're the same object. Using one name means a search for vi.mock finds every mock in the project.
By default the name is vi. Both the import and the calls are reported.
--fix renames the import and the calls.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"vitest/consistent-vitest-vi" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"vitest/consistent-vitest-vi" = ["error", {
fn = "vi",
}]Examples#
example.ts2 problems
import { expect, test, vitestThe vitest function accessor used is not allowed } from "vitest";
test("calls the listener", () => {
const listener = vitestThe vitest function accessor used is not allowed.fn();
emit("save", listener);
expect(listener).toHaveBeenCalled();
});example.tsNo problems
import { expect, test, vi } from "vitest";
test("calls the listener", () => {
const listener = vi.fn();
emit("save", listener);
expect(listener).toHaveBeenCalled();
});Options#
| Option | Default | What it does |
|---|---|---|
fn | "vi" | The name to use: "vi" or "vitest". |
With "vitest", vi is reported:
example.tswith
{ "fn": "vitest" }2 problemsimport { viThe vitest function accessor used is not allowed } from "vitest";
viThe vitest function accessor used is not allowed.useFakeTimers();