unreachable_from_main
Unreachable top-level members in executable libraries.
此规则自 Dart 2.19 版本起可用。
此规则提供 快速修复 。
详情
#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() {}
使用方法
#要启用 unreachable_from_main
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 unreachable_from_main
:
linter:
rules:
- unreachable_from_main
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.