avoid_ relative_ lib_ imports
Avoid relative imports for files in lib/
.
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';
...
Enable
#
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
If you're instead using the YAML map syntax to configure linter rules,
add
avoid_relative_lib_imports: true
under
linter > rules:
linter:
rules:
avoid_relative_lib_imports: true
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Report an issue.