◆ arch_guard

IDE warnings

Shows arch_guard rules as warnings on the offending import line, in VS Code, Android Studio / IntelliJ and dart analyze / flutter analyze, with quick fixes.

Warning When Quick fixes
layer_violation An import crosses a layer boundary that allowed_imports does not allow. Remove the import · Allow the import in the config
forbidden_package An import uses a package or core library listed under forbidden_packages. Remove the import
circular_dependency This import closes a cycle among files in lib/. It is the one import whose removal breaks the cycle, or shrinks it the most. Remove the import
module_violation An import reaches into another module’s private files, or into a module modules: allowed doesn’t list. See Module boundaries. Remove the import
workspace_violation An import between workspace members that workspace_rules doesn’t allow. See Workspace rules. Remove the import

Install

Requires Dart 3.10 / Flutter 3.38 or later.

# analysis_options.yaml
plugins:
  arch_guard_lint: ^0.4.0

Restart the Dart analysis server afterwards (in VS Code: Dart: Restart Analysis Server).

In a pub workspace

Dart reads plugins: only from the workspace root’s analysis_options.yaml, but it applies a member’s own analysis_options.yaml to that member’s files. A member with its own options file therefore gets no arch_guard warnings until it includes the root file:

# analysis_options.yaml at the workspace root
plugins:
  arch_guard_lint: ^0.4.0
# packages/core/analysis_options.yaml
include:
  - package:flutter_lints/flutter.yaml   # what the member already includes
  - ../../analysis_options.yaml          # the workspace root

Don’t add plugins: to a member’s file: Dart warns Plugins can only be specified in the root of a pub workspace there. Members without an analysis_options.yaml use the root file and need nothing.

Quick fixes

Open the quick-fix menu on a warning (VS Code: Ctrl+. / Cmd+.).

The fixes run one at a time, never in bulk or through dart fix. Removing an import or loosening a rule should be your call. There is no “allow” fix for forbidden_packages: weakening a “never import this” rule should be a deliberate edit.

Circular dependencies

circular_dependency uses the same cycle-breaking hint as the CLI. Each cycle gets one warning, on the import to remove:

warning - lib/domain/user.dart:1:8 - This import closes a circular dependency of 2 files: lib/domain/user_service.dart -> lib/domain/user.dart -> lib/domain/user_service.dart. Removing it breaks the cycle. Move the code both files need into a third file, or invert the dependency. - circular_dependency

To turn it off:

# analysis_options.yaml
plugins:
  arch_guard_lint:
    version: ^0.4.0
    diagnostics:
      circular_dependency: false

How it works

Suppress a single warning:

// ignore: arch_guard_lint/layer_violation
import '../data/repo.dart';

The CLI, CI and expectArchitecture() honour the same comment, so a silenced import does not fail the build either. The codes are layer_violation, forbidden_package, module_violation, workspace_violation and circular_dependency. To silence a code for a whole file:

// ignore_for_file: arch_guard_lint/circular_dependency