banned-imports
- Group
- Correctness
- Path
cross-file/correctness/banned-imports- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 191 of 512
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
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() {}import 'dart:io';import 'dart:io';import 'package:flutter/material.dart' show Widget;import 'package:flutter/material.dart' show Widget;import '../data/repository.dart';import '../data/repository.dart';import 'package:boundary_app/data/cache.dart';import 'package:boundary_app/data/cache.dart';import 'stub.dart' if (dart.library.io) 'dart:io';import 'stub.dart' if (dart.library.io) 'dart:io';import 'package:legacy/client.dart' deferred as legacy;import 'package:legacy/client.dart' deferred as legacy;import 'package:flutter/src/widgets/framework.dart' as widgets;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.io == 'true') 'package:flutter/io.dart' 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.
{
"cross-file": {
"rules": {
"correctness": {
"banned-imports": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore cross-file/correctness/banned-imports: <reason>More correctness rules
- cancel-subscriptions
cancel_subscriptionsrecommendedCancel instances of
dart:asyncStreamSubscription. - check-is-not-closed-after-async-gaprecommendedbloc
Flags Bloc
addandemitcalls after an await without a freshisClosedcheck. - close-sinks
close_sinksrecommendedClose instances of
dart:coreSink. - collection-methods-unrelated-type
collection_methods_unrelated_typerecommendedReports collection lookups whose argument type is unrelated to the collection's type argument.
- comment-references
comment_referencesrecommendedFlags doc-comment references
[name]that resolve to nothing in scope. - correct-order-for-super-dispose
correct_order_for_super_disposerecommendedflutterRequire
super.dispose()to be the last call indispose. - depend-on-referenced-packages
depend_on_referenced_packagesrecommendedcross-fileRequire imported packages to be declared in
pubspec.yaml. - deprecated-member-use-from-same-package
deprecated_member_use_from_same_packageReports uses of deprecated declarations from their own package.