unnecessary_ library_ directive
Details about the 'unnecessary_library_directive' diagnostic produced by the Dart analyzer.
Library directives without comments or annotations should be avoided.
Description
#
The analyzer produces this diagnostic when a library directive
doesn't have a documentation comment or any annotations.
If no documentation comment or annotation precedes the library directive, then either it's unnecessary or the documentation comment and/or annotations are misplaced and should be moved.
Examples
#
The following code produces this diagnostic because the library
directive doesn't have a documentation comment or annotation:
library;
class C {}
The following code produces this diagnostic because the library's
documentation comment is below the library directive:
library;
/// This library provides the [C] class.
/// The [C] class.
class C {}
Common fixes
#
If you don't want to add a documentation comment or annotation
to the library, then remove the library directive:
class C {}
If you intend to add a documentation comment or annotation,
then add or move it to the library directive:
/// This library provides the [C] class.
library;
/// The [C] class.
class C {}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.