-
Notifications
You must be signed in to change notification settings - Fork 889
member-ordering rule, alphabetize not working on getters and setters #3965
Comments
I'd be willing to fix this once #3935 is merged. |
As far as I can tell, getters and setters are currently being completely ignored. I could add separate categories "publicStaticGetter", "privateInstanceSetter" etc, or just treat getters and setters as instance variables. I think, in general, you'd want getter and setter for the same member to be together, but maybe want to enforce that getters come before setters. Unfortunately the current framework doesn't really allow this, as alphabetization is done last. So you'd have either: // getters have lower rank than setters:
get a() {}
get b() {}
set a(x) {}
set b(x) {}
// OR: getters have same rank as setters, alphabetized:
// corresponding getters and setters are together, however:
get a() {}
set a(x) {}
set b(x) {}
get b() {}
// getter after setter, but no warning. The above behavior could be acceptable... or I could just build in a hack and have "get a" be alphabetically be before "set a". Would anyone want setters before getters? Also, it might lead to weird errors messages... Any thoughts? |
Many thanks for taking the time to look at this issue. I think it would be interesting to have separate categories, as you comment. So they can be grouped separately from instance variables. I like to have getters and setters together, but it is a personal preference, although I would say is the most common case. I would prefer:
over:
It would be a significant improvement over current behavior. And I think it covers the scope of the current issue. Ideally, a perfect result would be:
but if it's hacky to achieve, maybe it's better to leave it as it is. Similar behavior happens with function overloads, where no particular order guaranteed.
Being able to take into account the method parameters when ordering would be cool. Mainly for overloading. But I think this is another enhancement/issue. |
Sorry if I wasn't clear above^^. The two examples would both be possible if separate categories were added for the getters and setters, the result are with alphabetization enabled or disabled. The order of overloads changes the semantics of the function, and as such should definitely not be changed by this rule. |
Any news on this? I'm looking forward to having this feature. |
Bug Report
member-ordering rule seems not to work properly on getters and setters.
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
No error
Expected behavior
tslint should report errors like:
Maybe this issue is somehow related to:
The text was updated successfully, but these errors were encountered: