Skip to content
← Back to rules

react/invariant 限制

功能

报告 React Compiler 内部不变量违规。这些问题表明编译器本身存在错误,而不是你的代码存在问题——请考虑向 oxc 或 React 团队报告。

由 React Compiler 提供支持,该编译器每个文件运行一次,并与其他 React Compiler 规则共享。移植自 react-hooks/invariant

为什么这很糟糕?

不变量违规意味着编译器的内部状态不一致;受影响的函数会被跳过,而不是进行优化。

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["react"],
  "rules": {
    "react/invariant": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["react"],
  rules: {
    "react/invariant": "error",
  },
});
bash
oxlint --deny react/invariant --react-plugin

版本

此规则在 vnext 中添加。

参考