-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Would like to be able to lint usages of "private-ish" APIs #33353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Brainstorming a few ways to make this more broadly useful. We could introduce @Friend("hello.template.dart");
@Component(
selector: 'my-comp',
template: 'Hello {{name}}!',
)
class MyComp {
@friendOnly
String name;
} Another similar encoding would be const _template = "hello.template.dart";
@Component(
selector: 'my-comp',
template: 'Hello {{name}}!',
)
class MyComp {
@VisibleTo(_template)
String name;
} Thoughts? Other ideas? |
Definitely, that's an option. I think I sort of didn't correctly explain the semantics, though, I'd need anything annotated with (Another option is |
Oh gotcha! That's funny ... I almost added a third example for @Component(
selector: 'my-comp',
template: 'Hello {{name}}!',
)
class MyComp {
@visibleToTemplate
String name;
} const visibleToTemplate = VisibleTo("*.template.dart"); ... but I figured that might be too much visibility. Sounds like it's actually the right level of visibility for Angular. EDIT: |
Yeah, that could work. To be clear, I think ultimately having proper visibility modifiers (as a language feature or annotations) or better yet, better static meta-programming, is my ideal solution. Until then though, I think something like |
RE: // defined in Angular package somewhere
import 'package:meta/meta.dart' show visibleForCodegen;
const visibleToTemplate = visibleForCodegen; I presume the linter has access to the resolved constant. (If it doesn't, it should.) |
That would also be fine to me. |
You're correct, it does. |
….dart`. This is intended to be a target for later work within the analyzer or linter package for linting/hinting improper public API usage, as outlined in the issue: dart-lang/sdk#33353. PiperOrigin-RevId: 201407857
….dart`. This is intended to be a target for later work within the analyzer or linter package for linting/hinting improper public API usage, as outlined in the issue: dart-lang/sdk#33353. PiperOrigin-RevId: 201407857
To clarify to stakeholders, we added this in We would now need support for the annotation added into the analyzer (or linter). |
I'll comment real quick on how this will interact with All three of these annotations read as "I wanted to make this member private, but it also should be accessible by X." So combining them just unions the added visibility over what private would have given:
|
Bug: #33353 Change-Id: Iaafccc3dca6b8d87bd54ed721871c72e9ac456c8 Reviewed-on: https://dart-review.googlesource.com/68432 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
This issue supersedes #29643 and would close angulardart/angular#930.
AngularDart requires all methods and fields in a
class
annotated with@Component()
arepublic
, so that the corresponding (generated)<file>.template.dart
can access those methods and fields.For example:
... generates, approximately the following ...
This is the only intended use of the
String name
field. For example, it could be tightly bound to other state, it isn't valid to be changed outside of the class's knowledge. If we madename
private (_name
), it would satisfy that requirement, but then could not be used from.template.dart
.So, this should lint:
Specification
<file>.template.dart
for<file>.dart
FAQ
Can't you just make
.template.dart
a part file?Theoretically. This would take multiple man years, which is much higher than the cost of adding this lint. It's possible we might go down this route eventually, but it should be considered at this point functionally impossible.
Can't this just live in the
angular_analyzer_plugin
Theoretically. We haven't found a good mechanism to run this, at build-time, in google3. Also not all users use the
angular_analyzer_plugin
(@MichaelRFairhurst should know precise numbers), so we'd need everyone to be able to see the impact of this (similar to Flutter's@required
).What about more "general" lints
If we ever implemented visibility keywords, or something like
@internal
or@visibleForCodegen
, or@friend[ly]
, and it would be able to at least mostly match the semantics expressed above then we would use them instead, and happily delete this lint or the request for this lint.Why is this important
For one, AngularDart currently heavily collides with "Effective Dart" (/cc @munificent). We're working on that - but one of the areas outside of our control this one. We'd much prefer we had an easily understandable standard way of saying "basically private":
... the alternative, or the status quo, is this:
The text was updated successfully, but these errors were encountered: