javascript - Eslint 在 for..of 循环中解构时抛出“no-undef”
问题描述
我正在使用 eslint 和一些定制的 airbnb 标准。
我的 eslintrc 文件,
module.exports = {
extends: 'airbnb-base',
rules: {
'no-restricted-syntax': 'off', // allow for..of loop
},
};
这是一个也有解构的示例循环。
for ({ bar: foo, baz: fiz, biz } of data) {}
Eslint 抛出错误,
'foo' is not defined. (no-undef)
'fiz' is not defined. (no-undef)
'biz' is not defined. (no-undef)
在for...of
反模式中这样做吗?
问题是无论我如何定义它都会引发错误。避免这种情况的唯一方法是,
for (const sample of data) {
let { bar: foo, baz: fiz, biz } = sample;
}
我不想禁用no-undef
,因为它对程序的其他领域非常重要。但是,我找不到有关此行为的资源或解释。
可能是因为我禁用了 no-restricted-syntax 并且 airbnb 没有针对这种行为的正确规则吗?
出于好奇,我浏览了repo,发现了一些有趣的问题,
- 不允许使用 'ForOfStatement' (no-restricted-syntax),但是我禁用了此规则,因此它不适用于此处。
解决方案
推荐阅读
- css - 需要帮助样式化 react-native-elements 输入组件
- coq - IndProp:ev_plus_plus
- java - AndroidRuntime:致命异常
- c - Makefile 和 C 代码之间的变量冲突
- binary - 图灵机比较多个二进制数
- java - JButton 图像渲染不好
- javascript - ReactJS 如何在状态下处理对象的方法?
- sql - 在具有不同 where 子句的子查询中查找百分比
- c# - 在 ASP.Net Core 中为 Web 部署“在目标位置删除其他文件”添加例外?
- reactjs - REDUX-REACT - 调度未定义