banned-imports

Path
cross-file/correctness/banned-imports
Default
Off, opt in
Origin
Falcon
Rule
191 of 512
cross-file

Cross-file rule. It runs in falcon's whole-project pass, analyzing relationships across every file rather than one file at a time. Configure it under the top-level cross-file key.

Report imports forbidden by package-relative architectural boundaries.

Configure rules: [{files: ["lib/domain/**"], deny: ["package:flutter/**"], message: "Keep domain code independent of Flutter."}] in this rule's options. Both lists are required, nonempty lists of nonempty glob strings; message is required and nonblank. Invalid entries are rejected during configuration validation; no configuration means no reports. Globs are case-sensitive, match the entire string, and use / separators: * does not cross directories, while ** does. Source files paths are relative to their nearest enclosing pubspec directory (including lib/). Files without an enclosing pubspec are skipped.

Each deny pattern matches the decoded import URI, without quotes, and the normalized package-relative target of relative or same-package imports. Local target matching does not require the target to exist. External package and SDK imports match only their URI. Primary and all conditional URIs are checked, including inactive alternatives; prefixes, deferred loading and combinators do not exempt an import. Each matching entry reports its custom message once per URI, even if several of its patterns match. Overlapping entries can therefore produce multiple reports. Exports and parts are not imports and are deliberately outside this rule's boundary policy.

Invalid

bad/lib/domain/bad.dartdart
import 'dart:io';
import 'package:flutter/material.dart' show Widget;
import '../data/repository.dart';
import 'package:boundary_app/data/cache.dart';
import 'stub.dart' if (dart.library.io) 'dart:io';
import 'package:legacy/client.dart' deferred as legacy;
import 'package:flutter/src/widgets/framework.dart' as widgets;
import '../domain/../data/missing.dart';
import 'stub.dart'
    if (dart.library.io == 'true') 'package:flutter/io.dart'
    if (dart.library.html) 'package:flutter/web.dart';

void main() {}
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
1import 'dart:io';
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
1import 'dart:io';
2import 'package:flutter/material.dart' show Widget;
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
2import 'package:flutter/material.dart' show Widget;
3import '../data/repository.dart';
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
3import '../data/repository.dart';
4import 'package:boundary_app/data/cache.dart';
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
4import 'package:boundary_app/data/cache.dart';
5import 'stub.dart' if (dart.library.io) 'dart:io';
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
5import 'stub.dart' if (dart.library.io) 'dart:io';
6import 'package:legacy/client.dart' deferred as legacy;
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
6import 'package:legacy/client.dart' deferred as legacy;
7import 'package:flutter/src/widgets/framework.dart' as widgets;
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
7import 'package:flutter/src/widgets/framework.dart' as widgets;
8import '../domain/../data/missing.dart';
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
9import 'stub.dart'
10 if (dart.library.io == 'true') 'package:flutter/io.dart'
bad/lib/domain/bad.dartKeep domain code independent of platform and data libraries.
10 if (dart.library.io == 'true') 'package:flutter/io.dart'
11 if (dart.library.html) 'package:flutter/web.dart';

Configure banned-imports

Set its severity in falcon.json under the cross-file section. See the configuration guide.

falcon.jsonjson
{
  "cross-file": {
    "rules": {
      "correctness": {
        "banned-imports": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore cross-file/correctness/banned-imports: <reason>