-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Unclear documentation of @internal #60732
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
I don't think the example given about "top level" is correct Afaik the lint only applies to public libraries. Given: @internal
class A {} Then if the source is located in Afaik the warning on top-level elements is on purpose. It's to tell packages that those should not be exported. But we can't easily do the same thing for class members, as Dart has no mean to do something like So a warning in those cases would make |
In short we have 3 things at play:
// my_package/lib/a.dart
class A {
@internal
int value
} // another_package/lib/main.dart
print(a.value); // warn
Such as: @internal // useless since private
class _A {}
IMO the docs could be improved by splitting the description in 3 parts ; one for each cause. |
But if, as in my example above, the definition is in
Could it not warn if the surrounding class was exported (as that implies the member is also exported). To me it is really confusing that the same annotation has two related but actually quite different meanings:
I can kind of see the use of both of these, but it is not clear why the same annotation has both of these meanings. Really I'd like a mode where you explicitly mark the elements you want to be public.... but that is another topic ... |
I'm an avid user of For example, I often use it inside code-generators. For that, I tend to do: // An annotation for using the code-generator
const myAnnotation = ...;
// Some utils that the generated code will rely on
@internal
class $Util {} Then the generated code will do: // ignore_for_file: internal_usage (or whatever the error code is)
part of 'file.dart';
// TODO: Use $Util somehow
Off topic, but I implemented such a lint for my own personal usage 3 weeks ago. It's a lint that's the reverse of TL;DR: // src/source.dart
@Public.inLibrary('misc.dart')
class A {}
class B {}
@internal
class C {} // my_package/lib/misc.dart
export 'src/source.dart' show A;
// my_package/lib/my_package.dart
export 'src/source.dart' show B; And this warns if:
One of the reasons I've implemented this is: It empowers |
Right - I think it would be useful with a third annotation for that (though I think it falls somewhat under the second use case I mentioned: "Help consumers of my package not importing this by mistake") |
I'm not sure I agree. I think it's just the annotation's name that is a bit unfortunate. I'd name it |
If you read the original design discussions of |
I suppose that it could, but it would be an interesting, and possibly confusing, new way to use annotations. We have annotations (such as
Interesting. We recently added a similar sort of lint for the analyzer package. Maybe it would be worth unifying them and making it more widely available. |
https://pub.dev/documentation/meta/latest/meta/internal-constant.html says
It seems the last line kind of contradicts the two others. That case should only happen if the other ones are not upheld.
Also it seems the analyzer only reports about top-level
@internal
elements being exported.The text was updated successfully, but these errors were encountered: