简体   繁体   English

在两个无限制语法违规之间捕获

[英]Caught between two no-restricted-syntax violations

This is my original code: 这是我的原始代码:

const buildTableContent = (settings) => {
  const entries = [];
  for (const key in settings) {
    for (const subkey in env[key]) {

settings is basically a dictionary of dictionary settings基本上是字典的字典

  {  
    'env': {'name': 'prod'}, 
    'sass: {'app-id': 'a123445', 'app-key': 'xxyyzz'}
  }

It triggered the following AirBnb style guide error: 它触发了以下AirBnb样式指南错误:

35:3 error for..in loops iterate over the entire prototype chain, which is virtually never what you want. 35:3错误for..in循环迭代整个原型链,这几乎不是你想要的。 Use Object.{keys,values,entries}, and iterate over the resulting array no-restricted-syntax 使用Object。{keys,values,entries},并迭代生成的数组无限制语法

So I change the code to 所以我将代码更改为

const buildTableContent = (settings) => {
  const entries = [];
  for (const key of Object.keys(settings)) {
    for (const subkey of Object.keys(env[key])) {

as suggested. 如建议。

Now when I run lint , I got this: 现在当我运行lint ,我得到了这个:

35:3 error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. 35:3错误迭代器/生成器需要再生器 - 运行时,这对于本指南来说太重了。 Separately, loops should be avoided in favor of array iterations no-restricted-syntax 另外,应避免循环,以支持数组迭代无限制语法

So it looks to me either way they are violating some lint style. 所以它看起来像他们违反了一些皮棉风格。

How can I fix this issue? 我该如何解决这个问题?

You'd want to use 你想用

Object.keys(settings).forEach(key => {
  Object.keys(env[key]).forEach(subkey => {

or potentially Object.entries or Object.values depending on if you actually want the keys. 或者可能是Object.entriesObject.values具体取决于您是否真的需要密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM