This package contains custom ESLint rules that we use here at Relevance AI. These rules aren't intended for public usage (some of them are quite specific and opinionated), so we don't recommend using them in your projects.
See the implementations for more specifics.
This rule errors when importing from both expect
and vitest
in the same file. When using vitest, you should use its version of expect()
.
This rule errors when a string literal or Function.name
is passed to Vitest's describe
function. You should pass the function directly, so the describe block name stays in-sync with the function name.
Bad:
function Foo() {}
describe('Foo', () => {})
function Foo() {}
describe(Foo.name, () => {})
Good:
function Foo() {}
describe(Foo, () => {})
This rule errors when passing a path to vi.mock
. You should pass an import expression instead as this:
- makes
vi.mock
type-safe since we can't refer to modules that don't exist. - allows TypeScript to infer the correct type for the mock factory (2nd arg to
vi.mock
). - makes refactoring by moving files around easier since VSCode updates import expressions when you do.
Bad:
vi.mock('~/dependencies', () => {})
Good:
vi.mock(import('~/dependencies'), () => {})
This rule errors when a variable, containing a function, doesn't have a PascalCase name. The rule was written to replace @typescript-eslint/naming-convention for our needs, since it was taking up about 25 seconds, or about 40%, of the time taken to lint one of our repos.
Bad:
const foo = () => {}
Good:
const Foo = () => {}
We intentionally don't generate fixes for the naming violations, since that would require analysing which parts of a variable are words/acronyms.