Import reaches into a package’s private src directory

ID

dart.maintainability.implementation_imports

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

medium

Resource

Encapsulation

Language

Dart

Description

Reports an import or export of a package: URI whose path starts with src/, the directory a Dart package uses for the implementation files it does not export.

Rationale

Everything under a package’s lib/src is private by convention: it is not part of the published API, so its authors change, rename and delete those files in patch releases without considering it a breaking change. Code that imports them is pinned to internals it does not control and can break on any dependency bump, with no deprecation window and nothing in the package’s changelog to warn about it.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Import reaches into a package's private src directory
import 'package:analyzer/src/dart/element/element.dart';

Remediation

Import the package’s public entry point instead - package:analyzer/dart/element/element.dart rather than package:analyzer/src/dart/element/element.dart. If what you need is not exported, ask the package to export it (or open an issue), rather than reaching past its API; as a last resort, vendor or reimplement the piece you need so the coupling is visible in your own code.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved