搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案