Skip to content

linter: add an option to unicorn/no-array-sort to allow [...iterable].sort() #20544

Description

@domenic

I like the idea behind the unicorn/no-array-sort rule. When I'm dealing with plain arrays, I'd like to turn it on.

However, often I am dealing with, e.g., a Set, which I want to convert to a sorted array. In such cases, my choices are:

const sortedArray = [...mySet].sort();     // faster, but trips the linter
const sortedArray = [...mySet].toSorted(); // double allocation, but makes linter happy

I'd like to have some option, e.g. { allowAfterSpread: true }, which specifically allows the [...spreadSomething].sort() pattern.

I'm willing to give a shot at contributing this (with the help of Claude Code) if I can get some signal it'll be accepted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions