Rule(s) Request unnecessary_open
and missing_final
#4838
Labels
discussion
Topics that cannot be categorized as bugs or enhancements yet. They require further discussions.
rule-request
Requests for a new rules.
New Issue Checklist
New rule request
The idea of
unnecessary_open
is that it would warn about uses ofopen
where it is not required, because the class, var, or function is never overridden outside its own module.missing_final
would warn whenever a class, var, or method was never overridden either inside or outside its own module, and can be safely declared asfinal
.Presumably these would need to be analyzer rules. Because the logic required is quite similar, it might be easier to combine them into one rule.
If
open
andfinal
are strictly enforced, then it becomes possible to tell from the declaration whether and where a class is ever subclassed, or a var of fun overridden, as opposed to whether they could be subclassed or overridden in theory.final
- never overriddeninternal or public
- overridden, but only within the same moduleopen
- overridden outside their defining module.Because unnecessary
open
's and missingfinal
s are not currently detected, in our own codebase, we were able to tighten these up very considerably when we did this analysis by hand.Triggering Examples
For
unnecessary_open
:For
missing_final
:Non-Triggering Examples:
For
unnecessary_open
:For
missing_final
:If combined into one rule, it would probably be good to allow them to be selectively enabled.
For libraries, where it is kind of expected that you will advertise your API, but not necessarily call it yourself, this could be a pain, but you can always disable it.
As an analyzer rule, by definition this would be opt-in.
Other notes:
Not entirely sure how you would unit test a rule like this that requires different compilation modules.
The text was updated successfully, but these errors were encountered: