react/jsx-no-undef Correctness
它的作用
禁止在 JSX 中使用未声明的变量。
请注意,如果你在使用 TypeScript,这条规则通常是不必要的,因为 TypeScript 会帮你捕获未声明的变量。
为什么这很糟糕?
这很可能是由于变量名或参数名拼写错误导致的潜在 ReferenceError。
示例
以下是此规则的错误代码示例:
jsx
const A = () => <App />;
const C = <B />;如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["react"],
"rules": {
"react/jsx-no-undef": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["react"],
rules: {
"react/jsx-no-undef": "error",
},
});bash
oxlint --deny react/jsx-no-undef --react-plugin版本
此规则是在 v0.1.1 中添加的。
