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
{
'env': {'name': 'prod'},
'sass: {'app-id': 'a123445', 'app-key': 'xxyyzz'}
}
It triggered the following AirBnb style guide error:
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
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:
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With