sbdchd / eslint-plugin-cake

:cake: Sweet rules for ESLint
MIT License
1 stars 0 forks source link

new rule: prefer-simple-object-enumeration #23

Open sbdchd opened 3 years ago

sbdchd commented 3 years ago
// err
for (const key of Object.keys(mapping)) {
  const value = mapping[key];
  // ...
}
for (const key of Object.keys(mapping) as (keyof MappingType)[]) {
  const value = mapping[key];
  // ...
}

// ok
for (const value of Object.values(mapping)) {
  // ...
}

I think we need to check if someone ids calling Object.keys() and then indexing into the variable they called Object.keys() on. Also need to check that they don't use key later in the block

similar: https://github.com/sbdchd/flake8-pie/issues/87