admin管理员组

文章数量:1201403

I have the Code for some iterations and it works well. After installing eslint, One of my code generates an error by eslint.

My code is:

for (const column of columns) {
    for (const slugname of result[column.name]) {
        const alphabet = slugname.slugname;
        if (total[alphabet]) {
            total[alphabet] += column.value;
        } else {
            total[alphabet] = column.value;
        }
    }
}

eslint generates an error which is this

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

Any help or suggestion is really appreciated for that. According to me The code was written very precisely and very small, don't know about the clue of eslint error

I have the Code for some iterations and it works well. After installing eslint, One of my code generates an error by eslint.

My code is:

for (const column of columns) {
    for (const slugname of result[column.name]) {
        const alphabet = slugname.slugname;
        if (total[alphabet]) {
            total[alphabet] += column.value;
        } else {
            total[alphabet] = column.value;
        }
    }
}

eslint generates an error which is this

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

Any help or suggestion is really appreciated for that. According to me The code was written very precisely and very small, don't know about the clue of eslint error

Share Improve this question asked Apr 25, 2019 at 8:07 AksAks 1,2243 gold badges15 silver badges37 bronze badges 5
  • Have you try not to use for ... of? – Chase Choi Commented Apr 25, 2019 at 8:14
  • no because for will handle much better than foreach – Aks Commented Apr 25, 2019 at 8:15
  • 1 would array.find() solve the issue? link – Edwin Commented Apr 25, 2019 at 8:28
  • Consider using .map()? – evolutionxbox Commented Apr 26, 2019 at 13:24
  • Consider using the .map() function, unless in the case where you want to iterate through an async block in series, in which case you should set up an ignore for this rule. – Willster Commented Nov 7, 2022 at 14:40
Add a comment  | 

2 Answers 2

Reset to default 19

There is nothing wrong with your code, this is outdated guidance.

"iterators/generators require regenerator-runtime" hasn't been true since 2014 caniuse.com/es6-generators this error looks like it came from airbnb's style guide and you'd have to ask them if they still stick to it

columns.map(x => result[x.name].map((y) => {
  const alphabet = y.slugname;
  if (total[alphabet]) {
      total[alphabet] += x.value;
    } else {
      total[alphabet] = x.value;
    }
    return true;
}));

本文标签: