eslint-plugin-command icon indicating copy to clipboard operation
eslint-plugin-command copied to clipboard

Keep-sorted Feature Enhancement (Map and Array)

Open wll8 opened this issue 11 months ago • 0 comments

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

  • [X] Follow our Code of Conduct
  • [X] Read the Contributing Guide.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

wll8 avatar Jan 09 '25 02:01 wll8