antfu / antfu/eslint-plugin-command

Keep-sorted Feature Enhancement (Map and Array)

Open
#33 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
371
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Clear and concise description of the problem

Add sorting for items in Map and Array.

Suggested solution
Support for Strings in Arrays

If there is support for objects in arrays, I believe it is also necessary to support strings in arrays.

Before implementation

// @keep-sorted
const arr = [
  `b`,
  `a`,
  `c`,
]

After implementation

// @keep-sorted
const arr = [
  `a`,
  `b`,
  `c`,
]

Currently, I can only use it like this

// @keep-sorted
const arr = objToArr({
  b: true,
  a: true,
  c: true,
})
Support for Map

Before

// @keep-sorted
const map = new Map([
  [`c`, `cc`],
  [`a`, `aa`],
])

After

// @keep-sorted
const map = new Map([
  [`a`, `aa`],
  [`c`, `cc`],
])
Adjust Sorting Rules

Expect the order a before a.b, rather than after, using ASCII ascending order.

Current Sorting

// @keep-sorted
const obj = {
  'a.1': true,
  'a': true,
  'b': true,
  'c': true,
}

Expected Sorting

// @keep-sorted
const obj = {
  'a': true,
  'a.1': true,
  'a.2': true,
  'b': true,
  'c': true,
}

If it conflicts with the currently implemented sorting method, could sorting be supported as a parameter?

Alternative

No response

Additional context

No response

Validations

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing @keep-sorted handling and its current sorting behavior. Reproduce the examples for string arrays, Map entries, and dotted keys, then determine how the requested ordering should interact with existing object sorting. Done means these cases are consistently sorted and covered by the project's relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.