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 {}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。