Skip to main content

avoid-importing-entrypoint-exports

added in: 1.7.0
⚙️🛠
Pro+

Warns when an entrypoint export is imported inside the library src folder.

Package entrypoint exports are considered the package public API. Depending on this API in the implementation is fragile and can easily introduce cyclic imports.

⚙️ Config

Set only-in-src (default is true) to checks files only within the src/ directory. Disabling this flag will also highlight entrypoint exports usages in test/.

analysis_options.yaml
dart_code_metrics:
rules:
- avoid-importing-entrypoint-exports:
only-in-src: true

Example

❌ Bad:

lib/src/some_class.dart
// LINT: Avoid importing entrypoint exports. Try importing the source file directly instead of importing the re-export.
import 'package:package/value.dart';

class SomeClass {}

✅ Good:

lib/src/some_class.dart
import 'package:package/src/path/to/value.dart'; // Correct, import from 'src'

class SomeClass {}