avoid_relative_lib_imports
Avoid relative imports for files in lib/
.
This rule is available as of Dart 2.0.
Rule sets: core, recommended, flutter
This rule has a quick fix available.
Details
#DO avoid relative imports for files in lib/
.
When mixing relative and absolute imports it's possible to create confusion
where the same member gets imported in two different ways. An easy way to avoid
that is to ensure you have no relative imports that include lib/
in their
paths.
You can also use 'always_use_package_imports' to disallow relative imports
between files within lib/
.
BAD:
import 'package:foo/bar.dart';
import '../lib/baz.dart';
...
GOOD:
import 'package:foo/bar.dart';
import 'baz.dart';
...
Usage
#To enable the avoid_relative_lib_imports
rule,
add avoid_relative_lib_imports
under linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_relative_lib_imports
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。