Skip to content

prefer-flat-map warns about and auto-fixes the wrong order of flat()/map() calls #25

@arild-haugstad

Description

@arild-haugstad

According to MDN --- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap --- and my quick tests in NodeJS and Firefox, flatMap() is equivalent with running flat() on the output of map(), not with running map() on the output of flat() which the rule warns about and rewrites from...

E.g. console.log([[1, 2], [3, 4]].flat().map((x) => x * 2)); outputs [2, 4, 6, 8], but is "autofixed" to console.log([[1, 2], [3, 4]].flatMap((x) => x * 2)); which outputs [NaN, NaN].

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions