infctr / eslint-plugin-typescript-sort-keys

A linter plugin to require sorting interface and string enum keys
ISC License
143 stars 25 forks source link

string-enum ignores comments #44

Open havenchyk opened 2 years ago

havenchyk commented 2 years ago

I noticed that string-enum rule ignores comments, so if you have comments on the right like

enum Events {
  MyEvent2 = 'My Event 2' // my event 2
  MyEvent1 = 'My Event 1' // my event 1

will become

enum Events {
  MyEvent1 = 'My Event 1' // my event 2
  MyEvent2 = 'My Event 2' // my event 1

which is wrong

Do you want to accept a PR for it?

infctr commented 2 years ago

@havenchyk Will appreciate a PR

RodrigoMural commented 2 years ago

I'm noticing the same thing with function props, is the PR in place?

BenJackGill commented 9 months ago

I'm noticing the same thing with interfaces.

The comment does not move with the property.

For example, we start with this interface that has unsorted keys.

interface Foo {
    zoo: number;
    bar: number; // I am a comment for the "bar" property
}

Using the autofix it will be incorrectly formatted to this. Note that the interfaces keys are now correctly sorted but the comment did not move so it is now in the wrong spot.

interface Foo {
    bar: number;
    zoo: number; // I am a comment for the "bar" property
}

I was expecting this to happen. The interface keys are correctly sorted and the comment has moved also.

interface Foo {
    bar: number; // I am a comment for the "bar" property
    zoo: number;
}
ChrisWiles commented 6 months ago

yeah, unfortunately this is a deal breaker for many people

BenJackGill commented 2 months ago

I keep coming up against this problem for comments on Interfaces. @havenchyk did your PR go anywhere?

BenJackGill commented 4 weeks ago

I am now using the amazing eslint-plugin-perfectionist for the same purpose.

It has alphabetical or natural sorting. Sorts everything; Interfaces, Objects, ect. Handles comments and more gracefully. Also very configurable to your exact needs.