geli
geli copied to clipboard
tslint.json: member-ordering has invalid value
User Story
As a: developer
I want: a consistent source code
The allowed values for member-ordering changed with some tslint update in the past. Currently the rule for member-ordering is ignored.
"member-ordering": [ true, "static-before-instance", "variables-before-functions" ],
I think we have the following options:
a) Set member-ordering to false (like many other projects https://github.com/buzinas/tslint-eslint-rules/blob/master/tslint.json or https://github.com/Glavin001/tslint-clean-code/blob/master/tslint.json)
b) Agree to new values and fix linting errors. I would like to recommend:
"member-ordering": [ true, { "order": "fields-first" } ]
This configuration forces fields before functions (a new variable between two functions would be a violation - see screenshot) and public before private (public, private & public would be a violation - see screenshot)
Today we have 18 (api) and 54 (frontend) violations for the suggested configuration. Its possible to enable certain tslint rules only for api or frontend.
Acceptance criteria:
- [ ] tslint.json without invalid values
- [ ] source comply with tslint
Additional info:
Predefined values for member-ordering are: fields-first, instance-sandwich and statics-first but its possible to configure a custom order if necessary. Read https://github.com/palantir/tslint/blob/master/src/rules/memberOrderingRule.ts#L46 for more information about the predefined values.
Normally you would have the followed ordering:
- public fields
- private fields
- public methods
- private methods
In Clean Code, Robert C. Martin advises coders to always put member variables at the top of the class (constants first, then private members) and methods should be ordered in such a way so that they read like a story that doesn't cause the reader to need to jump around the code too much. This is a more sensible way to organize code rather than by access modifier.
https://stackoverflow.com/questions/1760850/best-practice-ordering-of-public-protected-private-within-the-class-definition