react/unsupported-syntax 限制
功能
警告 React Compiler 不计划支持的语法,例如 eval;使用该语法的组件和钩子会被跳过,不会进行优化。
由 React Compiler 提供支持,该编译器每个文件运行一次,并与其他 React Compiler 规则共享。移植自 react-hooks/unsupported-syntax。
为什么这是个问题?
像 eval 这样的构造会使数据流无法分析,因此组件会永久放弃编译器优化。
示例
此规则中不正确的代码示例:
jsx
function Component(props) {
eval("props.x = true");
return <div />;
}此规则中正确的代码示例:
jsx
function Component(props) {
return <div>{props.x}</div>;
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["react"],
"rules": {
"react/unsupported-syntax": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["react"],
rules: {
"react/unsupported-syntax": "error",
},
});bash
oxlint --deny react/unsupported-syntax --react-plugin版本
此规则在 vnext 中添加。
