unnecessary_library_directive
Avoid library directives unless they have documentation comments or annotations.
Details
#DO use library directives if you want to document a library and/or annotate a library.
BAD:
dart
library;
GOOD:
dart
/// This library does important things
library;
dart
@TestOn('js')
library;
NOTE: Due to limitations with this lint, libraries with parts will not be flagged for unnecessary library directives.
Enable
#To enable the unnecessary_library_directive
rule,
add unnecessary_library_directive
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- unnecessary_library_directive
If you're instead using the YAML map syntax to configure linter rules,
add unnecessary_library_directive: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
unnecessary_library_directive: true
除非另有说明,文档之所提及适用于 Dart 3.7.2 版本,本页面最后更新时间: 2025-03-07。 查看文档源码 或者 报告页面问题。