Rule Request: strict_accessibility_modifier #4839
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
strict_accessibility
would warn where the current accessibility modifier was less restrictive that it could be, given the rest of the codebase.By enforcing accessibility strictly, declarations allow inference about how the code is used, as opposed to how it could be used.
For example, consider
here
bar
is visible asinternal
by default, but if it is never actually accessed outside its own class, then it could equally be declared as:This makes intent clearer.
This would presumably need to be an analyzer rule.
Enforcing accessibility as tightly as possible makes intent clearer, and can potentially help the compiler.
Triggering Violations:
Non-Triggering Violations:
Exactly as the triggering violations, but where the rest of the code determines that
Foo
orbar
must beinternal
, orprivate
, or whatever.Possibly configurable for which modifiers should be reported on. For example, warn me about
public
's, but don't warn me aboutinternal
's - I'm not sure I can see a use case for that though.Analyzer rule, so automatically opt-in I believe.
The text was updated successfully, but these errors were encountered: