Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If something should be sorted, move all above comments with that before a blank line or a non-comment entity is found #97

Open
2 tasks done
datismoa opened this issue Dec 20, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@datismoa
Copy link

datismoa commented Dec 20, 2023

What rule do you want to change?

sort-object-types, sort-objects, sort-classes, ...?

Describe the problem

When some entity is being sorted, move along with it not only the first comment, but all of them before a blank line or a non-comment entity is found

Code example

(natural sorting is used)

Example 1:

const test = {
  // yes 1
  // yes 2
  name: 'Immanuel',

  // first blablabla
  // second blablabla
  age: 79,

  // what a nice year
  bornYear: 1724,
}

to

const test = {
  // first blablabla
  // second blablabla
  age: 79,

  // what a nice year
  bornYear: 1724,

  // yes 1
  // yes 2
  name: 'Immanuel',
}

Example 2:

const test = {
  // :)
  /** 
   * yeah
   * works
   * too
   */
  status: 'who_knows',
  key: 'value', // sticked!
  // something more
  c: 'good!',
}

to

const test = {
  // something more
  c: 'good!',
  key: 'value', // sticked!
  // :)
  /** 
   * yeah
   * works
   * too
   */
  status: 'who_knows',
}

Example 3:

class Test {
  name: string

  // first blablabla
  // second blablabla
  age: number
}

to

class Test {
  // first blablabla
  // second blablabla
  age: number

  name: string
}

Example 4

type TTest = {
  b: string

  // wanna
  // be
  a: 123
}

to

type TTest = {
  // wanna
  // be
  a: 123

  b: string
}

Additional comments

Really needed this functionality, so I have hastily created a workaround. Repository: https://github.com/datismoa/eslint-plugin-perfectionist. Does not break any of tests, tho

Would be great if we had an option that regulates such behaviour & the ability to choose in what entities and how (for example, count a multiline comment as an inhibitor) it works

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@datismoa datismoa added the enhancement New feature or request label Dec 20, 2023
@danvk
Copy link

danvk commented Jan 20, 2024

This would also be helpful for keeping eslint-disable-next-line comments associated with the thing they are trying to disable:

class C {
  z = new Date();
  // eslint-disable-next-line perfectionist/sort-classes
  a = this.z;
}

(Context: #102)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants