通过 eslint-enable 重新启用文件内禁用的 eslint 规则

问题描述 投票:0回答:2

如果在

.eslintrc.js
配置中关闭了 lint 规则,我们能否以某种方式在特定文件中重新启用 lint 规则?

假设我有(.eslintrc.js):

module.exports = { // omiting extends and plugin etc... rules: { 'react-hooks/exhaustive-deps': 'off' } }
    
eslint eslintrc
2个回答
0
投票
所以

eslint-enable

看起来是正确的解决方案,不幸的是这不起作用。

// ❌DOESN'T WORK /* eslint-enable react-hooks/exhaustive-deps */ export const useCount = () => { const [value,setValue] = useState() const inc = useCallback(()=>{ setValue(value+1) // 🚨EXPECT ESLINT WARNING },[]) return {inc, value} }

不知道这是一个错误还是“按预期工作”行为......


0
投票
您需要在配置文件中使用

overrides

 属性(
.eslintrc.js
 或类似文件):

module.exports = { rules: { 'react-hooks/exhaustive-deps': 'off' // disabled for all files }, overrides: [ { files: [ 'your/file.js' ], rules: { 'react-hooks/exhaustive-deps': 'error' // enabled only for 'your/file.js' } } ] }
    
© www.soinside.com 2019 - 2024. All rights reserved.