vitest/valid-title Correctness
作用
检查 Jest 和 Vitest 块的标题是否有效。
标题必须:
- 不能为空,
- 必须是字符串,
- 不能以前面的块名作为前缀,
- 不能有开头或结尾的空格。
为什么这不好?
无效的标题可能会产生误导,并使理解测试目的变得更加困难。
示例
此规则的错误代码示例:
javascript
describe("", () => {});
describe("foo", () => {
it("", () => {});
});
it("", () => {});
test("", () => {});
xdescribe("", () => {});
xit("", () => {});
xtest("", () => {});此规则的正确代码示例:
javascript
describe("foo", () => {});
it("bar", () => {});
test("baz", () => {});选项
typescript
interface Options {
ignoreSpaces?: boolean;
ignoreTypeOfTestName?: boolean;
ignoreTypeOfDescribeName?: boolean;
allowArguments?: boolean;
disallowedWords?: string[];
mustNotMatch?: Partial<Record<"describe" | "test" | "it", string>> | string;
mustMatch?: Partial<Record<"describe" | "test" | "it", string>> | string;
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/valid-title": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/valid-title": "error",
},
});bash
oxlint --deny vitest/valid-title --vitest-plugin版本
此规则于 v0.0.14 中添加。
