prefer_relative_imports
Prefer relative imports for files in lib/
.
This rule is available as of Dart 2.6.
This rule has a quick fix available.
Incompatible rules: always_use_package_imports
Details
#PREFER 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. One way to avoid
that is to ensure you consistently use relative imports for files within the
lib/
directory.
BAD:
dart
import 'package:my_package/bar.dart';
GOOD:
dart
import 'bar.dart';
Usage
#To enable the prefer_relative_imports
rule,
add prefer_relative_imports
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- prefer_relative_imports
除非另有说明,文档之所提及适用于 Dart 3.5.3 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。