typescript/no-var-requires Restriction
它的作用
禁止 require 语句,但导入语句中的 require 除外。
注意:此规则有意缺少原始 typescript-eslint 规则中的 allow 选项。 此规则在上游插件中已弃用,应改用 typescript/no-require-imports 规则。
这为什么不好?
换句话说,像 var foo = require("foo") 这样的写法是被禁止的。请改用 ES module 导入,或使用 import foo = require("foo") 导入。
typescript
var foo = require("foo");
const foo = require("foo");
let foo = require("foo");如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"typescript/no-var-requires": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"typescript/no-var-requires": "error",
},
});bash
oxlint --deny typescript/no-var-requires版本
此规则是在 v0.0.7 中添加的。
