AGENT SKILL

Dart 文档注释校验

dart-doc-validation

验证 Dart 文档注释的最佳实践。涵盖使用 `dart doc` 检测未解析的引用和宏。

使用场景Dart 开发
License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 8
Forks
7

01 前言 Front Matter

name
dart-doc-validation
license
Apache-2.0
description
Best practices for validating Dart documentation comments. Covers using `dart doc` to catch unresolved references and macros.
key_features
[ "Documentation comment validation", "Unresolved reference checking", "Dart doc macro verification" ]

02 资源文件 1

03 SKILL.md 正文

Dart Doc Validation

1. When to use this skill

Use this skill when:

  • Writing or updating documentation comments (///) in Dart code.
  • Checking for broken documentation links, references, or macros.
  • Preparing a package for publishing to pub.dev.

When NOT to use (Abstention Guardrails)

Do NOT apply this skill or refactor doc comments when:

  • Illustrative Pseudo-Code & Non-Dart Code Fences: Comments contain pseudo-code, non-Dart language identifiers (e.g. yaml`, json, ````bash, ````text`), or abstract conceptual fragments intentionally not designed to compile as valid Dart.
  • Generated Code: Files generated by tools (e.g. *.g.dart, *.mocks.dart, *.freezed.dart) where comments are synthesized.
  • External Markdown Hyperlinks: Text in square brackets followed by a link target (e.g. [External Guide](https://...)), which is standard Markdown hyperlink syntax rather than an unresolved Dart doc reference.

Discovery

To find documentation issues:

Missing Lint

Verify if the comment_references lint is enabled:

  • Target: analysis_options.yaml
  • Search Query: comment_references

Automated Validation

Run the documentation generator to surface warnings:

  • Command: dart doc -o $(mktemp -d)
  • Keywords to look for: warning:, unresolved doc reference, undefined macro

2. Best Practices

Enable the doc validation lint

In your analysis_options.yaml, enable the comment_references lint.

linter:
  rules:
    - comment_references

Validating Documentation Locally

Use the dart doc command with a temporary output directory to validate documentation comments without polluting the local project workspace.

This command parses all documentation comments and reports warnings such as:

  • warning: unresolved doc reference
  • warning: undefined macro

Command to run:

dart doc -o $(mktemp -d)

This will work on Mac and Linux.

This ensures that the generated HTML files are stored in a temporary location and don't clutter the package directory, while still surfacing all validation warnings in the terminal output.

Browsing the docs:

Our docs use features designed to be run on a web server. If you want to browse the generated docs locally, install the dhttpd package.

dart install dhttpd
TMP_DIR=$(mktemp -d) && dart doc -o "$TMP_DIR" &&  dhttpd --path "$TMP_DIR"

(Or use another HTTP server, such as python3 -m http.server.)

Fixing Common Warnings

  • Unresolved doc reference: Ensure that any identifier wrapped in square brackets ([Identifier]) correctly points to an existing class, method, property, or parameter in the current scope or imported libraries.
  • Undefined macro: If using {@macro macro_name}, ensure that the template {@template macro_name} is defined in the same file or a file that is imported and visible to the documentation generator.

04 同仓库更多 Skills

google
google/skills_lint.dart

Dart 单元测试基础

dart-test-fundamentals

`package:test` 的核心概念与最佳实践。 涵盖 `test`、`group`、生命周期方法(`setUp`、`tearDown`)以及配置(`dart_test.yaml`)。

软件开发工程师Dart 开发
★ 8
google
google/skills_lint.dart

Dart 断言匹配器最佳实践

dart-matcher-best-practices

使用 `expect` 和 `package:matcher` 的最佳实践。 重点关注可读的断言、正确选择匹配器以及避免常见陷阱。

软件开发工程师Dart 开发
★ 8
google
google/skills_lint.dart

Dart 长行代码规范处理

dart-long-lines

处理 Dart 代码中长行以遵守 80 列规则的指南,即 `lines_longer_than_80_chars` lint 检查。

软件开发工程师Dart 开发
★ 8
google
google/skills_lint.dart

Dart 开发最佳实践

dart-best-practices

Dart 开发的通用最佳实践。涵盖代码风格、Effective Dart(有效的 Dart)和语言特性。

软件开发工程师Dart 开发
★ 8
google
google/skills_lint.dart

GitHub Issue 分类与整理

triage-github-issues

按类型和优先级对新的 GitHub issue 进行分类,询问缺失的详细信息,并关闭重复项。当被要求对 issue tracker 进行分类(triage)、添加标签或清理时使用。

软件开发工程师代码仓库协作管理
★ 8
google
google/skills_lint.dart

Dart 包版本发布

release-dart-package

准备并将 Dart 包的新版本发布到 pub.dev,涵盖从版本号提升到 GitHub release 的完整流程。当被要求创建(cut)、打标签(tag)或发布(publish)版本时使用。

软件开发工程师部署与发布管理
★ 8