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

Caught between two no-restricted-syntax violations

这是我的原始代码:

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

settings基本上是字典

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

它触发了以下爱彼迎风格指南错误:

35:3 error for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array no-restricted-syntax

所以我把代码改成

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

按照建议。

现在当我 运行 lint 时,我得到了这个:

35:3 error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax

所以在我看来,它们都违反了一些 lint 风格。

我该如何解决这个问题?

您想使用

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

或可能 Object.entriesObject.values 取决于您是否真的想要钥匙。