What's the correct behavior here? Ideal behavior would be to sort as usual while still preserving the initialization graph. Maybe slightly easier would be to preserve the relative order of any properties that reference another one in their initializer, or are referenced in an initializer.
Describe the bug
If a class's properties include initializers, then perfectionist/sort-classes must consider references between those properties when sorting them.
Sorting property
a
before propertyz
is incorrect ifz
referencesa
in its initializer (see code sample below).Code example
perfectionist/sort-classes reports an error on this class:
Autofixing the error "corrects" the class to this:
But this has a type error and
a
will be undefined at runtime.ESLint version
v8.56.0
ESLint Plugin Perfectionist version
v2.5.0
Additional comments
What's the correct behavior here? Ideal behavior would be to sort as usual while still preserving the initialization graph. Maybe slightly easier would be to preserve the relative order of any properties that reference another one in their initializer, or are referenced in an initializer.
Validations