vitest/padding-around-test-blocks 样式
功能
此规则要求在一个或多个 test/it 语句的前后各留出一行空行。
为什么这不好?
代码格式不一致会使代码更难阅读和理解。此规则有助于确保测试块在视觉上与其余代码分隔开来,从而更容易在查看测试文件时识别它们。
示例
此规则的错误代码示例:
js
const thing = 123;
test("foo", () => {});
test("bar", () => {});js
const thing = 123;
it("foo", () => {});
it("bar", () => {});此规则的正确代码示例:
js
const thing = 123;
test("foo", () => {});
test("bar", () => {});js
const thing = 123;
it("foo", () => {});
it("bar", () => {});使用方法
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vitest"],
"rules": {
"vitest/padding-around-test-blocks": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vitest"],
rules: {
"vitest/padding-around-test-blocks": "error",
},
});bash
oxlint --deny vitest/padding-around-test-blocks --vitest-plugin版本
此规则在 v1.75.0 中添加。
