Search packages, repositories and app categories

Package detailsv1.2.0

dart_code_metrics_annotations

Annotations for DCM.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
16.2K
Likes
4
Pub points
140

Install package

flutter pub add dart_code_metrics_annotations

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A set of annotations designed to work with Dart Code Metrics (DCM) to provide metadata for code analysis. These annotations help developers mark specific parts of their Dart code for enhanced inspection, such as ignoring certain rules or specifying custom metrics. They integrate seamlessly into Flutter and Dart projects across multiple platforms, enabling more precise control over static analysis. The package supports linting and code quality enforcement through configurable directives.

Use cases

  • Customizing lint rule behavior
  • Enhancing code quality checks
  • Integrating with CI/CD pipelines
  • Marking code sections for special analysis
  • Supporting team-wide coding standards
  • Improving maintainability through structured annotations

Key features

  • Provides DCM-specific annotations
  • Enables fine-grained control over analysis
  • Works with existing linter configurations
  • Supports multi-platform projects
  • Facilitates automated code reviews
  • Simplifies metric-based code governance

Suitable for

  • Dart and Flutter teams using DCM
  • Projects requiring strict code quality standards
  • CI/CD environments with automated linting
  • Developers seeking customizable analysis rules
  • Teams enforcing consistent coding practices
  • Projects aiming for long-term maintainability

Considerations

  • Requires Dart Code Metrics to be installed
  • Annotations are only effective when used with DCM
  • May require configuration updates in .analysis_options
  • Not standalone—depends on a larger toolchain
  • Limited utility without integration into analysis workflow
  • Best used in conjunction with other code quality tools

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Pub Version License package publisher

DCM Annotations

DCM is an advanced linter for Dart and Flutter that helps you analyze and improve your code quality. You can find all available lint rules here.

@Throws()

Used to annotate getters, methods, functions, parameters or local variables that can throw an exception (or multiple exceptions/errors) and therefore an invocation of such declarations must explicitly handle that exception.

For example:

@Throws()
void fn() { /* ... */ }

@Throws({IndexError})
void anotherFn() { /* ... */ }

void main() {
  try {
    fn(); // OK.
  } catch(_) {}

  fn(); // LINT.

  try {
    anotherFn(); // OK.
  } catch(_) {}

  try {
    anotherFn(); // LINT.
  } on Exception catch(_) {}
}

DCM will provide feedback if:

  • an invocation of a declaration with this annotation has unhandled exceptions
  • a declaration is not marked with this annotation, but can throw an exception
  • a declaration is marked with this annotation, but does not have any invocation that throws an exception

For more information, see the documentation for handle-throwing-invocations and prefer-correct-throws.

@AcceptedTypes()

Used to annotate fields or parameters that have a type Object, but should only receive a known subset of types (e.g. String and int).

For example:

void fn() {
  fn(1); // LINT
  SomeClass(false); // LINT
}

void fn(@AcceptedTypes({String, bool}) Object value) {}

class SomeClass {
  @AcceptedTypes({String, int})
  final Object field;

  const SomeClass(this.field);
}

DCM will provide feedback if an invocation receives an argument that does not match the type listed in the @AcceptedTypes().

For more information, see the documentation for pass-correct-accepted-types.

@mutated

Used to annotate parameters or variables that are changed/updated within the function/method body.

For example, the avoid-collection-mutating-methods and avoid-mutating-parameters rules will not trigger on annotated parameters and avoid-not-assignable-collection-types will include such parameters into its analysis.

DCM will provide feedback if the @mutated annotation is missing or unnecessary.

For more information, see the documentation for prefer-correct-mutated and other rules mentioned above.

How to use annotations

Take these steps to use annotations:

  1. Install this package as a regular dependency:

    dart pub add dart_code_metrics_annotations
    

    or:

    flutter pub add dart_code_metrics_annotations
    
  2. Enable rules that rely on DCM annotations and add those annotations to your code.

Categories

Source repository

Projects using this package