是的,通过eslint-plugin-react
您想要的规则是这个:https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md
来自文档:
此规则判断从React.useState()调用中分解的值和setter变量是否对称命名.
正确的例子:
import React from 'react';
export default function useColor() {
// useState call is destructured into value + setter pair whose identifiers
// follow the [thing, setThing] naming convention
const [color, setColor] = React.useState();
return [color, setColor];
}
在您的配置中:
...
"react/hook-use-state": [<enabled>, { "allowDestructuredState": <boolean> }]
...
如果出于某种原因您不想使用第三方插件,则可以判断该代码,并且您可以编写自己的规则.
绝对比必须在代码审查期间监管它好:)