Index of every page on this site: llms.txt
All skills
Run it yourself

Create, test, and integrate custom Dart and Flutter static analysis rules, lints, quick fixes, quick assists, and analyzer plugins using the official modern analysis_server_plugin package (Dart 3.10+ / Flutter 3.38+). Use when asked to create custom lint rules, enforce architectural or API constraints, build an analyzer plugin, provide quick fixes or assists, configure analysis_options.yaml plugins, or troubleshoot plugin execution.

Use this Skill: https://skilld.dev/gh/parsodyl/dart-create-analysis-plugin/dart-create-analysis-plugin

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈116 tokens for metadata: the name and description. ≈3.7k when used: this file. ≈5.4k more on demand in 4 files.

Description uses 5.8% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈466 characters, or 5.8%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Dart Custom Analysis Rules & Plugins with analysis_server_plugin

A comprehensive, production-grade guide for agents and developers to build, test, and activate custom static analysis rules, quick fixes, assists, and plugins using Dart's official modern analyzer plugin architecture (analysis_server_plugin), supported natively starting in Dart 3.10+ (Flutter 3.38+).


1. Official Documentation & Package Resources

Because older LLM training data often references the deprecated legacy analyzer_plugin or third-party custom_lint, always adhere to the official resources:

Deep Technical References Included in This Skill


2. Architecture Overview

  1. Top-Level plugins Declaration: Plugins are registered in analysis_options.yaml under the top-level plugins: key (never nested under analyzer:).
  2. Synthetic Package Execution: When the Dart Analysis Server starts, it generates a synthetic package under ~/.dartServer/.plugin_manager/<hash>, adds the plugin dependencies, runs dart pub upgrade, and compiles an AOT snapshot (plugin.aot) running in an isolated background isolate.
  3. Dual Coverage: Once activated, rules automatically report in:
    • Interactive IDEs (VS Code, IntelliJ IDEA, Android Studio) with inline squigglies, Problems tab entries, and quick fixes.
    • CLI Analysis (dart analyze, flutter analyze) for continuous integration (CI).

3. Scaffolding the Plugin Package

Always isolate the plugin in its own package (e.g. packages/my_analyzer_plugin or tools/my_lints):

Option A: 1-Command CLI Scaffolding (Recommended)

Run the bundled Dart script (resolve <skill_dir> to the directory containing this SKILL.md file):

dart <skill_dir>/scripts/scaffold_plugin.dart --name my_analyzer_plugin --rule avoid_empty_catch

Option B: Manual Setup

Create a new package and add the required dependencies via dart pub add so Pub resolves versions compatible with your active Dart SDK (verified for Dart 3.10+ / Flutter 3.38+):

dart pub add analysis_server_plugin analyzer analyzer_plugin
dart pub add --dev analyzer_testing test test_reflective_loader lints

Or configure pubspec.yaml directly:

# pubspec.yaml
name: my_analyzer_plugin
description: Custom static analysis rules, fixes, and assists.
version: 0.1.0
publish_to: none

environment:
  sdk: ^3.10.0

dependencies:
  analysis_server_plugin: ^0.3.0
  analyzer: '>=8.0.0 <20.0.0'
  analyzer_plugin: '>=0.13.0 <1.0.0'

dev_dependencies:
  analyzer_testing: ^0.4.0
  lints: '>=5.0.0 <7.0.0'
  test: ^1.25.0
  test_reflective_loader: ^0.6.0

[!NOTE] Isolating the plugin in its own package prevents analyzer package constraints from conflicting with production application dependencies (e.g., code generators like build_runner or freezed).


4. Full Plugin Entrypoint & Capabilities

The plugin entrypoint MUST be located at lib/main.dart and expose a top-level plugin variable.

// lib/main.dart
import 'dart:async';
import 'package:analysis_server_plugin/plugin.dart';
import 'package:analysis_server_plugin/registry.dart';

import 'src/rules/my_rule.dart';
import 'src/fixes/my_fix.dart';
import 'src/assists/my_assist.dart';

final plugin = MyPlugin();

class MyPlugin extends Plugin {
  @override
  String get name => 'My Plugin';

  @override
  FutureOr<void> register(PluginRegistry registry) {
    // 1. Warning Rules: Enabled by default when the plugin is listed
    registry.registerWarningRule(MyRule());

    // 2. Lint Rules: Disabled by default; must be explicitly enabled in analysis_options.yaml
    registry.registerLintRule(MyOptionalLintRule());

    // 3. Quick Fixes: Associates a code correction with a specific diagnostic code
    registry.registerFixForRule(MyRule.code, MyFixProducer.new);

    // 4. Quick Assists: Contextual IDE refactorings/code actions
    registry.registerAssist(MyAssistProducer.new);
  }

  @override
  FutureOr<void> start() {
    // Optional startup initialization per analysis context
  }

  @override
  FutureOr<void> shutDown() {
    // Optional cleanup on plugin termination
  }
}

5. Implementing Analysis Rules

Rules inspect AST nodes and report diagnostics.

Single-Code Rule (AnalysisRule)

// lib/src/rules/my_rule.dart
import 'package:analyzer/analysis_rule/analysis_rule.dart';
import 'package:analyzer/analysis_rule/rule_context.dart';
import 'package:analyzer/analysis_rule/rule_visitor_registry.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/error/error.dart';

class MyRule extends AnalysisRule {
  // CRITICAL: Instantiate LintCode as a `static const` field.
  // The server relies on instance identity to match diagnostics for // ignore: comments.
  static const LintCode code = LintCode(
    'my_rule',
    'Problem description highlighting {0}.',
    correctionMessage: 'Try correcting the issue this way.',
    uniqueName: 'LintCode.my_rule',
    // Optional: defaults to DiagnosticSeverity.INFO; can be set to .WARNING or .ERROR
  );

  MyRule()
      : super(
          name: 'my_rule',
          description: 'A concise summary of what this rule enforces.',
        );

  @override
  DiagnosticCode get diagnosticCode => code;

  @override
  void registerNodeProcessors(
    RuleVisitorRegistry registry,
    RuleContext context,
  ) {
    final visitor = _Visitor(this, context);
    // Register the AST nodes to visit (e.g. addMethodDeclaration, addClassDeclaration, etc.)
    registry.addMethodDeclaration(this, visitor);
  }
}

class _Visitor extends SimpleAstVisitor<void> {
  final AnalysisRule rule;
  final RuleContext context;

  _Visitor(this.rule, this.context);

  @override
  void visitMethodDeclaration(MethodDeclaration node) {
    // 1. Filter out irrelevant elements (e.g., static, private, operators)
    if (node.isStatic || node.name.lexeme.startsWith('_')) {
      return;
    }

    // 2. Robust AST hierarchy navigation:
    // Avoid fragile `node.parent as ClassDeclaration` casts because intermediate AST nodes
    // (such as BlockClassBody) may sit between a member and its enclosing ClassDeclaration.
    // Always use `thisOrAncestorOfType`:
    final classDecl = node.thisOrAncestorOfType<ClassDeclaration>();
    if (classDecl == null) {
      return;
    }

    // 3. Inspect semantic elements and types
    final element = node.declaredFragment?.element;
    if (element == null) {
      return;
    }

    // 4. Report violation at the target token or node
    final isViolation = /* check custom condition */;
    if (isViolation) {
      rule.reportAtToken(node.name, arguments: [node.name.lexeme]);
    }
  }
}

Multi-Code Rule (MultiAnalysisRule)

When a rule can report multiple distinct diagnostic codes:

class MyMultiRule extends MultiAnalysisRule {
  static const codeA = LintCode('my_rule_a', 'Issue A message');
  static const codeB = LintCode('my_rule_b', 'Issue B message');

  MyMultiRule() : super(name: 'my_multi_rule', description: '...');

  @override
  List<DiagnosticCode> get diagnosticCodes => [codeA, codeB];

  // In visitor: rule.reportAtToken(node.name, diagnosticCode: codeA);
}

6. Implementing Quick Fixes & Quick Assists

Both Quick Fixes and Quick Assists subclass ResolvedCorrectionProducer, accept {required super.context}, and declare their CorrectionApplicability.

Quick Fix (ResolvedCorrectionProducer with FixKind)

Bound to a specific diagnostic code via registry.registerFixForRule(MyRule.code, MyFixProducer.new):

// lib/src/fixes/my_fix.dart
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analysis_server_plugin/edit/dart/dart_fix_kind_priority.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';

class MyFixProducer extends ResolvedCorrectionProducer {
  static const _fixKind = FixKind(
    'my_plugin.fix',
    DartFixKindPriority.standard, // or integer priority like 50
    'Apply automatic fix',
  );

  MyFixProducer({required super.context});

  @override
  CorrectionApplicability get applicability =>
      CorrectionApplicability.singleLocation;

  @override
  FixKind get fixKind => _fixKind;

  @override
  Future<void> compute(ChangeBuilder builder) async {
    await builder.addDartFileEdit(file, (fileBuilder) {
      fileBuilder.addReplacement(range.node(node), (editBuilder) {
        editBuilder.write('replacementCode()');
      });
    });
  }
}

Quick Assist (ResolvedCorrectionProducer with AssistKind)

Contextual IDE code action available at the user's cursor via registry.registerAssist(MyAssistProducer.new):

// lib/src/assists/my_assist.dart
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analyzer_plugin/utilities/assist/assist.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';

class MyAssistProducer extends ResolvedCorrectionProducer {
  static const _assistKind = AssistKind(
    'my_plugin.assist',
    30,
    'Wrap with custom handler',
  );

  MyAssistProducer({required super.context});

  @override
  CorrectionApplicability get applicability =>
      CorrectionApplicability.singleLocation;

  @override
  AssistKind get assistKind => _assistKind;

  @override
  Future<void> compute(ChangeBuilder builder) async {
    final targetNode = node;
    final nodeText = utils.getNodeText(targetNode);

    await builder.addDartFileEdit(file, (fileBuilder) {
      fileBuilder.addReplacement(range.node(targetNode), (editBuilder) {
        editBuilder.write('wrap($nodeText)');
      });
    });
  }
}

7. Automated Unit Testing with analyzer_testing

Use package:analyzer_testing to write isolated, deterministic unit tests without launching the full analysis server:

// test/my_rule_test.dart
// ignore_for_file: non_constant_identifier_names

import 'package:analyzer_testing/analysis_rule/analysis_rule.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:my_analyzer_plugin/src/rules/my_rule.dart';

void main() {
  defineReflectiveSuite(() {
    defineReflectiveTests(MyRuleTest);
  });
}

@reflectiveTest
class MyRuleTest extends AnalysisRuleTest {
  @override
  void setUp() {
    rule = MyRule();

    // Stub external package dependencies or base types
    newPackage('my_core').addFile('lib/my_core.dart', r'''
abstract class BaseType {}
''');

    super.setUp();
  }

  Future<void> test_validCode() async {
    await assertNoDiagnostics(r'''
import 'package:my_core/my_core.dart';

class ValidClass extends BaseType {
  void validMethod() {}
}
''');
  }

  Future<void> test_invalidCode() async {
    await assertDiagnostics(
      r'''
import 'package:my_core/my_core.dart';

class InvalidClass extends BaseType {
  void badMethod() {}
}
''',
      [
        lint(85, 9), // offset (85) and character length (9) of 'badMethod'
      ],
    );
  }
}

Run test suite:

dart test

8. Activating and Configuring in Projects

In the root analysis_options.yaml of the target project or workspace:

1. By Local Path (Monorepo / Local Development)

plugins:
  my_analyzer_plugin:
    path: ../my_analyzer_plugin

2. By Pub.dev Version Constraint

plugins:
  my_analyzer_plugin: ^1.0.0

3. By Git Repository

plugins:
  my_analyzer_plugin:
    git:
      url: https://github.com/my-org/my-plugin.git
      ref: main
      path: packages/plugin_dir

4. Configuring Specific Diagnostics

plugins:
  my_analyzer_plugin:
    path: ../my_analyzer_plugin
    diagnostics:
      my_rule: true               # Explicitly enable lint rule
      noisy_warning_rule: false   # Disable default warning rule

5. In-Code Diagnostic Suppression

Diagnostics generated by modern plugins use the <plugin_name>/<diagnostic_name> format:

// ignore: my_analyzer_plugin/my_rule
void someFlaggedMethod() {}

// ignore_for_file: my_analyzer_plugin/my_rule

9. Verification & Cache Maintenance

  1. Verify CLI: Run dart analyze or flutter analyze from the project root.
  2. Reload IDE:
    • IntelliJ / Android Studio: Click Restart Dart Analysis Server (the circular refresh icon in the Dart Analysis window).
    • VS Code: Run Dart: Restart Analysis Server from the Command Palette (Cmd+Shift+P / Ctrl+Shift+P).
  3. Clear Plugin Cache: If code edits inside the plugin package fail to reflect in the analysis server:
    rm -rf ~/.dartServer/.plugin_manager
    Restarting the analysis server will rebuild the synthetic package and recompile plugin.aot.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts17d3 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill is a comprehensive developer resource for building Dart and Flutter analysis plugins. It includes technical documentation, code templates, and a scaffolding script for generating project structures. All detected behaviors are consistent with its stated purpose of professional software development and utilize standard, trusted official resources from the Dart SDK ecosystem.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

Signed by skilld at 1f7585d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 3 weeks ago

README badge

README badge for parsodyl/dart-create-analysis-plugin