Skip to content

Why is forEach discouraged? #86

@zeke

Description

@zeke

I am using this linter in a project and it raised an issue about code like this:

apples
  .filter(apple => !apple.bad)
  .forEach(doSomething)

A for loop would have been messy in this context as the forEach had a number of const declarations. I ended up working around it by changing the forEach to map.

What is the motivation for this rule? My guess is that forEach doesn't play nicely with async functions, but I'm not sure. The current doc doesn't provide any explanation of the rationale: https://github.com/github/eslint-plugin-github/blob/master/docs/rules/array-foreach.md

cc @github/product-docs-engineering
cc @josh @koddsson @keithamus

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions