搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目