unreachable_ from_ main
Learn about the unreachable_from_main linter rule.
Unreachable top-level members in executable libraries.
Details
#
Any member declared in an executable library should be used
directly inside that library. An executable library is a
library that contains a main top-level function
or that contains a top-level function annotated with
@pragma('vm:entry-point')). Executable libraries
are not usually imported and it's better to avoid defining
unused members.
This rule assumes that an executable library isn't imported by
other libraries except to execute its
main function.
BAD:
main() {}
void f() {}
GOOD:
main() {
f();
}
void f() {}
Enable
#
To enable the unreachable_from_main rule, add
unreachable_from_main under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- unreachable_from_main
If you're instead using the YAML map syntax to configure
linter rules, add
unreachable_from_main: true under
linter > rules:
linter:
rules:
unreachable_from_main: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.