---
name: dart-analyzer-plugins
description: Use for custom Dart linter/analyzer plugin tasks.
version: 0.1.0
author: Hermes Agent
license: MIT
metadata:
  hermes:
    tags: [dart, flutter, linter, ci, static-analysis]
---

# Dart Analyzer Plugin Workflow

## When to Use

When a recurring code pattern is identified as a bug source (e.g., timezone, API misuse) and the user requests a systemic enforcement mechanism (custom linter) rather than a local point fix.

## Always-on rules

- **Systemic over local:** Basti rejects 'Hotfixes' if the underlying pattern can recur. A custom linter/analyzer plugin is the preferred solution for enforceable code quality constraints.
- **Native over legacy:** Since Dart 3.10+, use `analysis_server_plugin` (native). The older `custom_lint` package is archived and should not be used for new plugins.
- **CI Visibility:** The goal of a lint rule is to make violations visible in the CI/CD pipeline (via `flutter analyze`).

## Procedure

1. **Setup (Plugin Package):** Create a `lints/` sub-package inside the main project. Update `pubspec.yaml` with dependencies on `analysis_server_plugin` and the latest `analyzer` package.
2. **Rule Implementation (`AnalysisRule`):**
   - Extend the `AnalysisRule` class.
   - Define a `LintCode` static const with the rule name and error message.
   - Register the rule in the plugin entrypoint (`lib/main.dart`) using `registry.registerLintRule(...)`.
3. **AST Visitor Logic:**
   - Extend `SimpleAstVisitor` to traverse the AST.
   - Register node processors in `registerNodeProcessors`.
4. **Integration:** Add the plugin to the project's `analysis_options.yaml` under the `plugins:` section.
5. **Deployment:** Commit, push branch, and open a PR. The CI pipeline must run `flutter analyze` to surface rule violations.

## Pitfalls

- **API Volatility:** The `analyzer` package (AST) changes significantly between major versions (e.g., 10 -> 14). `InterfaceType`, `NamedArgument`, and `arguments2`/`argumentExpression2` must be used in the latest versions.
- **Syntax:** Avoid using invalid pattern syntax in closures (e.g., `case` in a simple closure); use type-safe, standard Dart flow control instead.
- **Local Environment:** `flutter` is not always in PATH in fresh terminal sessions. Always use the absolute path: `/opt/data/installs/flutter/bin/flutter`.
- **Pub Cache:** Located at `/opt/data/home/.pub-cache/hosted/pub.dev/`, not under the Flutter SDK directory.

## Support

- See `references/analyzer-ast-api.md` for a quick mapping of old vs. new API signatures.
