-
Notifications
You must be signed in to change notification settings - Fork 54
Description
Describe the bug
If a class definition has both static members and public members, the sorting will seemingly group all public fields first (prioritising static over public instance fields), then group public methods next, prioritising static methods over public instance methods.
As a user, when I'm reading code, the static and instance members are different contexts and almost different domains.
If I'm looking at static fields, I don't expect to be distracted by interleaved public fields - especially if there is a high number of public fields - which will have the result of pushing the remaining static methods way down below the rest of the public fields.
Additionally, the sorting just feels wrong (see bField, cField, aField below 🤔 😕 ).
Ideally, we'd co-locate all static members together - static fields, followed by static methods - presumably at the head, before all other public instance members.
class {
// Static fields group
// Static methods group
// Public fields group
// Public methods group
// ...rest
}Then my brain can be soothed and not get confused by this lack of natural perfection.
Code example
Current (and not very "natural")
export default class MyClass {
static bField = 'bfield';
static readonly cField = 'cfield';
aField = 'hi';
static myFunOne() {
console.log('Hello World!');
}
static myFunTwo() {
console.log('Hello World!');
}
instancFunc() {
console.log('instance func');
}
}Expected (more "natural")
export default class MyClass {
static bField = 'bfield';
static readonly cField = 'cfield';
static myFunOne() {
console.log('Hello World!');
}
static myFunTwo() {
console.log('Hello World!');
}
aField = 'hi';
instancFunc() {
console.log('instance func');
}
}ESLint version
9.34
ESLint Plugin Perfectionist version
4.15
Additional comments
No response
Validations
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.