sindresorhus/eslint-plugin-unicorn

Rule proposal: `no-duplicate-loops`

Open

#846 opened on Sep 30, 2020

View on GitHub
 (24 comments) (7 reactions) (0 assignees)JavaScript (5,022 stars) (468 forks)user submission
help wantednew rule

Description

I've seen this a couple of times

Error

for (const gamma of bars.map(alpha => alpha.beta.gamma)) {
  gamma('ray')
}
 
for (const act of actions.filter(act => typeof act === 'function')) {
  act('a fool')
}

Pass

for (const alpha of bars) {
  alpha.beta.gamma('ray')
}


for (const act of actions) {
  if (typeof act === 'function') {
    act('a fool')
  }
}

Contributor guide