eslint-plugin-perfectionist
eslint-plugin-perfectionist copied to clipboard
If something should be sorted, move all above comments with that before a blank line or a non-comment entity is found
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
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
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: https://github.com/azat-io/eslint-plugin-perfectionist/issues/102)
Fixed in bd8ba3f. Released in v3.6.0.