antfu / eslint-plugin-command

Comment-as-command for one-off codemod with ESLint.
https://eslint-plugin-command.antfu.me/
MIT License
190 stars 10 forks source link

`keep-sorted` for subset of object keys #23

Open TomerAberbach opened 1 month ago

TomerAberbach commented 1 month ago

Clear and concise description of the problem

For example, suppose you have:

const object = {
  // Group of entries
  b: true,
  c: true,
  a: true,

  // Other group of entries
  z: true,
  x: true,
  y: true,
}

It would be nice if I could add keep-sorted above a group of entries to sort them separately. Right now adding the comment above one of the groups results in:

[keep-sorted] error: Unable to find object/array/interface to sort  command/command

Suggested solution

Allow keep-sorted above a group of entries

Alternative

No response

Additional context

No response

Validations

TomerAberbach commented 1 month ago

I'd be willing to venture into the code and make a PR if you like the idea!

antfu commented 1 month ago

I am not sure about the complexity. But if you don't mind the effort, feel free to send a PR so we can discuss it. I do like the start and end marker like you proposed in #24

TomerAberbach commented 1 month ago

Sounds good. Not 100% sure yet when I'll have time to try it out, but hoping to make an attempt at the start/end marker approach soon :)