搜索插件、代码仓与 APP 分类

插件详情v1.2.0

dart_code_metrics_annotations

DCM 的注释。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.6万
喜欢数
4
Pub 分数
140

安装插件

flutter pub add dart_code_metrics_annotations

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一组用于与 Dart Code Metrics (DCM) 配合使用的注解,为代码分析提供元数据。这些注解帮助开发者标记其 Dart 代码中的特定部分,以进行更深入的检查,例如忽略某些规则或指定自定义度量标准。该包可无缝集成到跨多个平台的 Flutter 和 Dart 项目中,实现对静态分析的更精确控制。该包通过可配置的指令支持 linting 和代码质量强制执行。

适合场景

  • 自定义 lint 规则行为
  • 增强代码质量检查
  • 与 CI/CD 流水线集成
  • 标记代码段以进行特殊分析
  • 支持团队级编码规范
  • 通过结构化注解提高可维护性

主要特点

  • 提供 DCM 特定的注解
  • 启用对分析的细粒度控制
  • 与现有的 linter 配置兼容
  • 支持多平台项目
  • 促进自动化代码审查
  • 简化基于度量的代码治理

适合对象

  • Dart 和 Flutter 团队使用 DCM
  • 需要严格代码质量标准的项目
  • 带有自动 linting 的 CI/CD 环境
  • 寻求可自定义分析规则的开发者
  • 强制执行一致编码规范的团队
  • 致力于长期可维护性的项目

使用建议

  • 需要安装 Dart Code Metrics
  • 注释仅在与 DCM 配合使用时才有效
  • 可能需要在 .analysis_options 中更新配置
  • 非独立的——依赖于更大的工具链
  • 在未集成到分析工作流程的情况下,实用性有限
  • 最好与其他代码质量工具结合使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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.

所属分类

源码仓库

使用此插件的项目