dart-write-documentation

视觉设计 / 插画 界面 · 动效 · 设计品味 1 文件 EN 原文

Rules and formatting guidelines for writing Dart

Rules and formatting guidelines for writing Dart /// API documentation and doc comments. Use when documenting Dart code, writing doc comments for any Dart declaration (libraries, classes, methods, variables, etc.), or when instructed to follow the Effective Dart documentation guidelines.

说明语言:英文

来源flutteragent-plugins ↗ 查看原文件 ↗版权归原作者,请遵循原仓库许可
安装
npx skills add https://github.com/flutter/agent-plugins --skill dart-write-documentation

需要已安装 skills CLI。也可以直接从源仓库 clone。

在星云中查看 ↗
SKILL.md 原文

name: dart-write-documentation description: "Rules and formatting guidelines for writing Dart /// API documentation and doc comments. Use when documenting Dart code, writing doc comments for any Dart declaration (libraries, classes, methods, variables, etc.), or when instructed to follow the Effective Dart documentation guidelines." ---

Writing Dart API Documentation

Contents

When asked to write or update documentation for Dart code, you must strictly follow these formatting rules based on the "Effective Dart: Documentation" guidelines.

1. Scope and Structure

2. Tone and Openers

3. Strict Anti-Patterns (Banned)

4. Technical Placement & Resolution

5. Linking and Markdown

6. Verification

After writing or updating doc comments:

  1. Run dart analyze to ensure all bracketed references resolve properly without triggering comment_references warnings.
  2. (Optional) Run dart doc to verify the generated documentation renders cleanly.

Examples

1. Banned Tags vs. Prose

Bad:

/// This method fetches data.
/// @param force true to force reload.
/// @return the data
/// @throws NetworkException if host is unreachable.
Data load(bool force) { ... }

Good:

/// Fetches the remote data.
///
/// If [force] is true, this bypasses the local cache and forces a
/// network request.
///
/// Throws a [NetworkException] if the host is unreachable.
Data load(bool force) { ... }

2. The Annotation Placement Trap

Bad:

@override
/// Renders the widget to the screen.
Widget build(BuildContext context) { ... }

Good:

/// Renders the widget to the screen.
@override
Widget build(BuildContext context) { ... }

3. Openers and Tone

Bad:

/// Gets if the connection is active.
bool get isActive => _active;

/// This method initializes the connection.
void init() { ... }

Good:

/// Whether the connection is active.
bool get isActive => _active;

/// Initializes the connection.
void init() { ... }

4. Constructor Linking

Bad:

/// Creates a new user. Similar to calling [User()].
User.create() { ... }

Good:

/// Creates a new user. Similar to calling [User.new].
User.create() { ... }

5. Out-of-Scope Links (@docImport)

Bad:

import 'package:http/http.dart'; // Adds unnecessary runtime dependency just for docs

/// To use this, you must pass a [Client].

Good:

/// @docImport 'package:http/http.dart';
library;

/// To use this, you must pass a [Client].
同类技能
accessibilityaccessibility-complianceanimateanimate-expoanimation-performanceanimation-vocabularyanti-ui-slopapple-design
本页内容来自开源项目 flutter, 版权归原作者所有。
本站仅作技能索引与分享,所有 Skill 版权归其原作者所有。