Allow member accessibility even for public #34
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the scenes architecture we heavily use classes (and we use classes heavily already in core Grafana for data sources and other components).
We do allow protected and private member accessibility but not public, this to me creates unaligned/inconsistent code.
I think we should allow the public accessibility modifier. I know it is the default behavior, and it does not add any runtime behavior. It does provide great value.
It makes it super clear that the author actually thought about the intended use the function. When we only allow private/protected it's not always clear for functions that miss this keyword. Maybe the author just forgot? But a function that has the public keyword it becomes much more clear that the function is intended to be used from the outside.
It also makes code cleaner / and easier to read when all functions have modifiers:
Our current rules enforce this:
And does not allow this:
Here it is very clear that the intent of the author that the method is to be used from outside
Looking at other large typescript code bases they usually allow public keywords. The vscode code base does NOT enforce member accessibility so it's a bit inconsistent (some classes use public on all public methods some classes don't). I think that inconsistency is the only downside. The upside is that developers who want to be clear in the code they write, can and are allowed to.