eslint-plugin-typescript-sort-keys icon indicating copy to clipboard operation
eslint-plugin-typescript-sort-keys copied to clipboard

string-enum ignores comments

Open havenchyk opened this issue 4 years ago • 6 comments

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?

havenchyk avatar Oct 20 '21 11:10 havenchyk

@havenchyk Will appreciate a PR

infctr avatar Oct 20 '21 11:10 infctr

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

RodrigoMural avatar Feb 18 '22 12:02 RodrigoMural

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;
}

BenJackGill avatar Sep 29 '23 06:09 BenJackGill

yeah, unfortunately this is a deal breaker for many people

ChrisWiles avatar Dec 08 '23 16:12 ChrisWiles

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

BenJackGill avatar Apr 11 '24 02:04 BenJackGill

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.

BenJackGill avatar May 31 '24 06:05 BenJackGill