Rules / Correctness / implementation-imports

implementation-imports

lint/correctness/implementation-imports
recommended
Same as implementation_imports · Dart lints

Disallow importing another package's private src/ files.

Flags a package: import that reaches into another package's src/ directory, such as import 'package:other/src/internal.dart'. Everything under a package's lib/src/ is private implementation detail, not part of its public API, and may change or vanish in any release without notice. Depending on it couples your code to internals the author never promised to keep stable. Import only the package's public libraries — the files directly under lib/. Imports into your own package's src/ are allowed; the owning package is inferred from the file's path.

Invalid

example.dartdart
import 'package:foo/src/internal.dart';
import 'package:bar/src/helper.dart';
import 'package:baz/src/util/log.dart';
import 'package:collection/src/list.dart';
import 'package:http/src/client.dart';

void main() {}
Don't import implementation files from another package ('foo').
1import 'package:foo/src/internal.dart';
Don't import implementation files from another package ('bar').
1import 'package:foo/src/internal.dart';
2import 'package:bar/src/helper.dart';
Don't import implementation files from another package ('baz').
2import 'package:bar/src/helper.dart';
3import 'package:baz/src/util/log.dart';
Don't import implementation files from another package ('collection').
3import 'package:baz/src/util/log.dart';
4import 'package:collection/src/list.dart';
Don't import implementation files from another package ('http').
4import 'package:collection/src/list.dart';
5import 'package:http/src/client.dart';

Valid

example.dartdart
import 'package:foo/foo.dart';
import 'package:bar/widgets.dart';
import 'dart:async';
import 'src/local_helper.dart';
import 'package:baz/baz.dart';

void main() {}

How to configure

Set the severity of implementation-imports in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "implementation-imports": "error"
      }
    }
  }
}