代码之家  ›  专栏  ›  技术社区  ›  Md. Abu Taher

Eslint在for..of循环中解构时抛出'no unde'

  •  1
  • Md. Abu Taher  · 技术社区  · 7 年前

    我正在使用eslint和一点定制的airbnb标准。

    module.exports = {
      extends: 'airbnb-base',
      rules: {
        'no-restricted-syntax': 'off', // allow for..of loop
      },
    };
    

    这是一个示例循环,它也有解构功能。

    for ({ bar: foo, baz: fiz, biz } of data) {}
    

    '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

    这可能是因为我禁用了无限制语法,而airbnb没有针对此类行为的正确规则吗?

    0 回复  |  直到 7 年前