Relative import path reaches into a lib directory
ID |
dart.portability.avoid_relative_lib_imports |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Portability |
Language |
Dart |
Description
Reports an import or export whose URI is a relative path that descends into a lib directory, such as '../lib/shared.dart' or '../../other_package/lib/api.dart'.
Rationale
Everything under lib is addressable as a package: URI, and that is the identity Dart uses for it. Reaching the same file by walking the filesystem gives it a second identity, so the analyzer treats it as a different library: instance checks against the same class fail, top-level and static state exists twice, and private members no longer match. When the path crosses into another package’s lib, it also bypasses the dependency declared in pubspec.yaml entirely, so the import resolves on the developer’s machine and fails wherever the packages are laid out differently.
The following code illustrates the pattern detected by this rule:
// FLAGGED: Relative import path reaches into a lib directory
import '../lib/shared.dart';