搜尋套件、儲存庫與 APP 分類

套件詳情v5.1.0

dependency_validator

檢查遺失、未充分提升、過度提升和未使用之相依性。

macOSWindowsLinux
近 30 天下載
32.2萬
喜歡數
286
Pub 分數
110

安裝套件

flutter pub add dependency_validator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter/Dart 開發工具,用於分析專案相依性,以識別遺漏、未充分提升、過度提升及未使用之相依性。它透過標記可能導致建置失敗或套件過大之問題,協助維護乾淨且高效能的 pubspec.yaml 檔案。該工具透過簡單的命令列介面,無縫整合至開發工作流程中,特別適用於管理具有複雜相依性樹狀結構之大型程式碼庫的團隊。由 Workiva 所打造,支援 macOS、Windows 及 Linux 平台。

適用情境

  • 確保 pubspec.yaml 的準確性
  • 檢測未使用的依賴項
  • 防止因缺少依賴項而導致建構失敗
  • 在團隊專案中保持相依性潔淨
  • 識別錯誤的依賴項提升層級

主要特色

  • 即時依賴分析
  • 支援多個平台
  • 簡單的 CLI 結合
  • 清除問題報告
  • 開源,公開倉儲

適合對象

  • Flutter 開發者
  • 團隊專案維護者
  • CI/CD 流水線整合者
  • 大規模 Dart 應用
  • 程式碼品質倡導者

使用建議

  • 需要手動執行或設定 CI
  • 可能需要為複雜的依賴結構進行設定
  • 不是全面測試的替代品
  • 僅限依賴項驗證
  • 依賴於正確的 pubspec.yaml 語法

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Dependency Validator

A tool to help you find missing, under-promoted, over-promoted, and unused dependencies.

Installation

dart pub global activate dependency_validator

Usage

dart pub global run dependency_validator

This will report any missing, under-promoted, over-promoted, and unused dependencies. Any package that either provides an executable or a builder that will be auto-applied via the dart build system will be considered used even if it isn't imported.

  • Missing: When a dependency is used in the package but not declared in the pubspec.yaml
  • Under-promoted: When a dependency is used within lib/, bin/, or hook/ but only declared as a dev_dependency.
  • Over-promoted: When a dependency is only used outside lib/, bin/, and hook/ but declared as a dependency.
  • Unused: When a dependency is not used in the package but declared in the pubspec.yaml.

Hook scripts in hook/ (for example, build.dart and link.dart) run at build/link time (dart build, flutter build), so their imports must be regular dependencies. To opt out, use ignore to suppress warnings for a specific package name (for example, a dev_dependency used only in hooks), or exclude: ["hook/**"] to skip scanning the hook directory entirely (which also skips missing-dependency checks in hook files).

Configuration

There may be packages that are intentionally depended on but not used, or there may be directories that need to be ignored. You can statically configure these things in a dart_dependency_validator.yaml file in the root of your package:

# dart_dependency_validator.yaml

# Set true if you allow pinned packages in your project.
allow_pins: true
# Exclude one or more paths from being scanned. Supports glob syntax.
exclude:
  - "app/**"
# Ignore one or more packages.
ignore:
  - analyzer

[!Note] Previously this configuration lived in the pubspec.yaml, but that option was deprecated because pub publish warns about unrecognized keys.

Pub Workspaces (monorepos)

This package supports Pub Workspaces, a collection of packages in one repository. Workspaces allow Pub to share dependencies between your packages. Your top-level package's pubspec.yaml should have a workspace field that indicates which sub-packages should be included, like this:

workspace:
  - pkg1
  - pkg2

and your sub-packages should have resolution: workspace in their pubspec.yamls. For more information, see the linked documentation.

Running dependency_validator will always validate the package your terminal is in. If you run the tool on the top-level workspace package, it will analyze the workspace package and its sub-packages. To just analyze a sub-package, run the tool in its folder, or pass the -C argument:

$ dart run dependency_validator -C pkg1

所屬分類

依賴

依賴清單 13 項

原始碼儲存庫

使用此套件的專案