-
Notifications
You must be signed in to change notification settings - Fork 701
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
[2.19] Update documentation on Dart library directive to include non-name libraries #4314
Comments
To give a little summary here, because there's really nothing to this, haha: We already have a "library directive" which can be written above imports, like Previously the name was used in part files, and in mirrors, both of which are older style / soft-deprecated. So an exciting use for this feature is really just some code like /// A really great test library.
@TestOn('browser')
library;
... |
I think the documentation impact might be simply checking if we have any library directives in our docs that have annotations or doc comments, and if so, update those to use use the new |
@mit-mit – likely. Just good to double-check. |
I have a question: Is there a reason to explicitly name libraries at all anymore? One note in the docs says:
I'm assuming that is now the case for unnamed It also seems like the only use for named libraries might be In another thread Lasse says: "Giving a library a name is only really useful for avoiding duplicate imports with different paths, so most libraries do not use the declaration." But if that's really the only reason for naming libraries, wouldn't a unique URI bypass that anyway? I'm asking because information about the library directive is spread out all over the place and it's pretty inefficient to write "you can name them but don't need to unless you want to use |
@MaryaBelanger – not really. If you're using The ONLY (good) reason for library is |
Ok might be a little drastic but I'm going to add an Effective Dart: Usage section that says something like "DO only use the |
There's already a linter rule (that words it much better!): https://dart.dev/tools/linter-rules#unnecessary_library_directive
Though maybe "DON'T" is the better word, for "things that are almost never a good idea" |
Yeah there's a linter rule. That's great. But we should update the style guide, too. |
cc @munificent |
Honestly, it's probably not even worth adding to "Effective Dart". There are an infinite number of bad things we could tell users not to do but if the bad thing takes effort to do and doesn't have any even perceived upside, we don't usually tell them not to because they just... won't. :) We can add a guideline against it if others think it's useful, but I'm always a little worried about "Effective Dart" getting so many rules that people just tune it out entirely. |
So this linter rule cites But I noticed there's not a linter rule that's just like
I feel like this is a different concern than what the There's also this lint, @kevmoo any thoughts since you added the lint? |
@munificent Good point.
How does that sound? Done, here: dbac48c |
LGTM.
Tracking issue: dart-lang/linter#3882. |
fixes #4314 staged: https://lib-dir-docs.web.app Changes: - Added [code sample](https://lib-dir-docs.web.app/guides/language/effective-dart/documentation#consider-writing-a-library-level-doc-comment) to existing library-level doc comment section - Added [Don't use library directives unless attaching doc comments or annotations](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#dont-use-library-directives-unless-attaching-doc-comments-or-annotations) section - Added [Don't explicitly name libraries](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#dont-explicitly-name-libraries) section - Reduced [`part of`](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#do-use-strings-in-part-of-directives) section - Removed / modified unnecessary notes about the library directive on the [Creating packages](https://lib-dir-docs.web.app/guides/libraries/create-library-packages) page I thought about completely removing the `part of` section in Effective Dart: Usage, in favor of the more general new section "Don't explicitly name libraries", because it's not even recommended to use `part of` at all anymore. The new section could add a code example similar to the one for `part of` that more generally illustrates "Use URI strings to refer to libraries", and the linter rule could point to that section instead. Thoughts? @kevmoo @pq etc. Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
Fixing PRs merged into v2.19 |
fixes #4314 Changes: - Added [code sample](https://lib-dir-docs.web.app/guides/language/effective-dart/documentation#consider-writing-a-library-level-doc-comment) to existing library-level doc comment section - Added [Don't use library directives unless attaching doc comments or annotations](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#dont-use-library-directives-unless-attaching-doc-comments-or-annotations) section - Added [Don't explicitly name libraries](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#dont-explicitly-name-libraries) section - Reduced [`part of`](https://lib-dir-docs.web.app/guides/language/effective-dart/usage#do-use-strings-in-part-of-directives) section - Removed / modified unnecessary notes about the library directive on the [Creating packages](https://lib-dir-docs.web.app/guides/libraries/create-library-packages) page I thought about completely removing the `part of` section in Effective Dart: Usage, in favor of the more general new section "Don't explicitly name libraries", because it's not even recommended to use `part of` at all anymore. The new section could add a code example similar to the one for `part of` that more generally illustrates "Use URI strings to refer to libraries", and the linter rule could point to that section instead. Thoughts? @kevmoo @pq etc. Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
Fixes #4314 Changes: - Added [code sample](https://dart.dev/guides/language/effective-dart/documentation#consider-writing-a-library-level-doc-comment) to existing library-level doc comment section - Added [Don't use library directives unless attaching doc comments or annotations](https://dart.dev/guides/language/effective-dart/usage#dont-use-library-directives-unless-attaching-doc-comments-or-annotations) section - Added [Don't explicitly name libraries](https://dart.dev/guides/language/effective-dart/usage#dont-explicitly-name-libraries) section - Reduced [`part of`](https://dart.dev/guides/language/effective-dart/usage#do-use-strings-in-part-of-directives) section - Removed / modified unnecessary notes about the library directive on the [Creating packages](https://dart.dev/guides/libraries/create-library-packages) page Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
Fixes #4314 Changes: - Added [code sample](https://dart.dev/guides/language/effective-dart/documentation#consider-writing-a-library-level-doc-comment) to existing library-level doc comment section - Added [Don't use library directives unless attaching doc comments or annotations](https://dart.dev/guides/language/effective-dart/usage#dont-use-library-directives-unless-attaching-doc-comments-or-annotations) section - Added [Don't explicitly name libraries](https://dart.dev/guides/language/effective-dart/usage#dont-explicitly-name-libraries) section - Reduced [`part of`](https://dart.dev/guides/language/effective-dart/usage#do-use-strings-in-part-of-directives) section - Removed / modified unnecessary notes about the library directive on the [Creating packages](https://dart.dev/guides/libraries/create-library-packages) page Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
Fixes #4314 Changes: - Added [code sample](https://dart.dev/guides/language/effective-dart/documentation#consider-writing-a-library-level-doc-comment) to existing library-level doc comment section - Added [Don't use library directives unless attaching doc comments or annotations](https://dart.dev/guides/language/effective-dart/usage#dont-use-library-directives-unless-attaching-doc-comments-or-annotations) section - Added [Don't explicitly name libraries](https://dart.dev/guides/language/effective-dart/usage#dont-explicitly-name-libraries) section - Reduced [`part of`](https://dart.dev/guides/language/effective-dart/usage#do-use-strings-in-part-of-directives) section - Removed / modified unnecessary notes about the library directive on the [Creating packages](https://dart.dev/guides/libraries/create-library-packages) page Co-authored-by: Parker Lougheed <parlough@gmail.com> Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
See dart-lang/language#1073
Ask @srawlins for clarification
The text was updated successfully, but these errors were encountered: