unnecessary_library_name
Don't have a library name in a library
declaration.
此规则自 Dart 3.4 版本起可用。
_规则集:recommended , flutter _
此规则提供 快速修复 。
详情
#DON'T have a library name in a library
declaration.
Library names are not necessary.
A library does not need a library declaration, but one can be added to attach library documentation and library metadata to. A declaration of library;
is sufficient for those uses.
The only use of a library name is for a part
file to refer back to its owning library, but part files should prefer to use a string URI to refer back to the library file, not a library name.
If a library name is added to a library declaration, it introduces the risk of name conflicts. It's a compile-time error if two libraries in the same program have the same library name. To avoid that, library names tend to be long, including the package name and path, just to avoid accidental name clashes. That makes such library names hard to read, and not even useful as documentation.
BAD:
/// This library has a long name.
library magnificator.src.helper.bananas;
library utils; // Not as verbose, but risks conflicts.
GOOD:
/// This library is awesome.
library;
part "apart.dart"; // contains: `part of "good_library.dart";`
使用方法
#要启用 unnecessary_library_name
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 unnecessary_library_name
:
linter:
rules:
- unnecessary_library_name
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.