dangling_library_doc_comments
Dangling library doc comment.
Description
#The analyzer produces this diagnostic when a documentation comment that appears to be library documentation isn't followed by a library
directive. More specifically, it is produced when a documentation comment appears before the first directive in the library, assuming that it isn't a library
directive, or before the first top-level declaration and is separated from the declaration by one or more blank lines.
Example
#The following code produces this diagnostic because there's a documentation comment before the first import
directive:
/// This is a great library.
import 'dart:core';
The following code produces this diagnostic because there's a documentation comment before the first class declaration, but there's a blank line between the comment and the declaration.
/// This is a great library.
class C {}
Common fixes
#If the comment is library documentation, then add a library
directive without a name:
/// This is a great library.
library;
import 'dart:core';
If the comment is documentation for the following declaration, then remove the blank line:
/// This is a great library.
class C {}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.