tools: enable (sensible) additional eslint rules
This PR proposes enabling some additional rules that the project either already follows or probably should follow. Here’s the full overview:
no-lonely-if
If an if statement is the only statement in the else block, it is often clearer to use an else if form.
This one required some fix ups in existing code but IMO it's a good rule to have. Often these end up being a result of refactoring where the maintainer doesn't spot that the inner conditional block can be pulled out into an else if
. (I personally had this come up on a recent PR.)
https://eslint.org/docs/rules/no-lonely-if
for-direction
for loop with a stop condition that can never be reached, such as one with a counter that moves in the wrong direction, will run infinitely. While there are occasions when an infinite loop is intended, the convention is to construct such loops as while loops. More typically, an infinite for loop is a bug.
I don't think this is particularly controversial. If someone tries to write code that does go against this rule they should probably refactor or it'll be hard/impossible to follow in the future.
https://eslint.org/docs/rules/for-direction
accessor-pairs
It’s a common mistake in JavaScript to create an object with just a setter for a property but never have a corresponding getter defined for it. Without a getter, you cannot read the property, so it ends up not being used.
Again, not something that's an issue currently and if someone does do this, it's very likely an error or they should just go ahead and override.
https://eslint.org/docs/rules/accessor-pairs
symbol-description
This rule requires a description when creating symbols
This one is only enabled for lib
since I don't think we particularly care about this for doc
or test
. We already follow it but will be good to have for any potential future contributors.
https://eslint.org/docs/rules/symbol-description
(Side-note: is this tools
, build
or something else? Had no clue what to label the commit with.)
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
doc, lib, test, tools