unicorn/no-empty-file 正确性
它的作用
禁止不包含任何有意义代码的文件。
这包括仅由以下内容组成的文件:
- 空白字符
- 注释
- 指令(例如,
"use strict") - 空语句(
;) - 空块(
{}) - Hashbang(
#!/usr/bin/env node)
为什么这不好?
没有可执行或可导出内容的文件通常是无意产生的,或者是重构后遗留下来的。它们会让代码库显得杂乱,并且可能会误导工具或开发者,让人以为它们有作用,实际上并没有。
示例
以下是此规则的错误代码示例:
js
js
// 注释js
/* 注释 */js
"use strict";js
js
{
}js
#!/usr/bin/env node以下是此规则的正确代码示例:
js
const x = 0;js
"use strict";
const x = 0;js
const x = 0;js
{
const x = 0;
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-empty-file": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-empty-file": "error",
},
});bash
oxlint --deny unicorn/no-empty-file版本
此规则在 v0.0.15 中新增。
