vitest/prefer-to-have-length
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-to-have-length": "error",
},
},
];expect(files.length).toBe(1);expect(files.length).toEqual(1);expect(files.length).not.toStrictEqual(1);expect(files).toHaveLength(1);
expect(files).not.toHaveLength(1);
expect(files.name).toBe("report.txt");Examples from the Biome documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
vitest/prefer-to-have-length
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-to-have-length": "error",
},
},
];vitest/prefer-to-have-length
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-to-have-length": "error"
}
}nursery/useExpectToHaveLength
nursery · since 2.6.9
{
"linter": {
"rules": {
"nursery": {
"useExpectToHaveLength": "error"
}
}
}
}Suggest using toHaveBeenCalledTimes()
Enforce that all tests are in a top-level describe