eslint/id-denylist 风格
功能
禁止使用指定的标识符
为什么这是不好的?
通用名称可能导致代码难以理解。此规则允许你指定不允许使用的标识符名称列表,以避免这种情况。
示例
此规则的错误代码示例:
js
/*eslint id-denylist: ["error", "data", "callback"] */
const data = { ...values };
function callback() {
// ...
}
element.callback = function () {
// ...
};
const itemSet = {
data: [...values],
};
class Foo {
data = [];
}
class Bar {
#data = [];
}
class Baz {
callback() {}
}
class Qux {
#callback() {}
}此规则的正确代码示例:
js
/*eslint id-denylist: ["error", "data", "callback"] */
const encodingOptions = { ...values };
function processFileResult() {
// ...
}
element.successHandler = function () {
// ...
};
const itemSet = {
entities: [...values],
};
callback(); // 所有函数调用都会被忽略
foo.callback(); // 所有函数调用都会被忽略
foo.data; // 所有非赋值的属性名都会被忽略
class Foo {
items = [];
}
class Bar {
#items = [];
}
class Baz {
method() {}
}
class Qux {
#method() {}
}配置
类型:array
默认值:[]
使用方法
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"id-denylist": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"id-denylist": "error",
},
});bash
oxlint --deny id-denylist版本
此规则在 v1.76.0 中新增。
