dart-best-practices
General best practices for Dart development. Covers code style, effective Dart, and language features.
Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines.
$ npx -y skills add kevmoo/dash_skills --skill dart-test-coverage --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/dart-test-coverageContext preview
The summary Claude sees to decide when to auto-load this skill.
Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines.
name: dart-test-coverage description: |- Understand and improve test coverage in a Dart package. Helps agents run coverage, interpret results, and identify missed lines. key_features: - LCOV report collection - Missed line identification - Coverage analysis & improvement
Guidelines for running and interpreting test coverage in Dart packages.
Do NOT collect or demand test coverage for:
protobufs).
entrypoints that require specific physical hardware or OS services not available in the execution environment.
`example/` or developer maintenance scripts under `tool/` unless the package explicitly mandates 100% repository-wide coverage.
the broken tests first before collecting or reporting coverage.
To find areas lacking test coverage:
Follow the workflow to generate and interpret coverage data:
1. **Run Tests with Coverage**: `dart test --coverage=.dart_tool/coverage` 2. **Interpret Results**: Use the script or `format_coverage` as described in the **Interpreting Results** section to identify specific files and missed lines.
1. Ensure tests pass by running `dart test`. 2. Collect coverage by running `dart test --coverage=.dart_tool/coverage`. 3. Interpret the results using the provided script or standard tools. 4. Add tests to cover missed lines.
Run the following command to collect coverage in JSON format:
dart test --coverage=.dart_tool/coverage
> [!NOTE] We use `.dart_tool/coverage` as the output directory because > `.dart_tool` is typically already ignored in `.gitignore` files.
> [!TIP] For projects with complex conditional logic, you can pass the > `--branch-coverage` flag to `dart test` to collect branch-level coverage.
This repository includes a zero-dependency script that parses the raw JSON output and provides a summary of covered percentage and missed lines.
Run it from the project root (adjust path to script as needed):
dart run skills/dart-test-coverage/scripts/interpret_coverage.dart .dart_tool/coverage <package_name>
Replace `<package_name>` with the name from `pubspec.yaml`.
Example Output:
package:my_pkg/src/file.dart: 50.0% (2/4 lines) Missed lines: 3, 4
If `package:test` is installed, `package:coverage` is likely available as a transitive dependency. You can use its `format_coverage` tool.
To get a human-readable "pretty print" of the coverage:
dart run coverage:format_coverage --in=.dart_tool/coverage --out=stdout --pretty-print --report-on=lib
This will output the file content with hit counts on the left (e.g., `0|` for missed lines).
When presenting coverage results to the user, follow these guidelines:
1. **State the high-level percentage first** to give immediate context. 2. **Identify specific files and missed lines** clearly. 3. **Translate line numbers to code**: Don't just say "lines 3-6 are missed". Look at the source file and tell the user which functions or blocks are untested (e.g., "The `divide` function is missing coverage"). 4. **Propose concrete fixes**: Provide example test code that the user can immediately apply to cover the missed lines. 5. **Use tables for multi-file summaries**: When reporting on multiple files, use a markdown table with columns for File, Coverage %, and Missed Lines to make the summary easy to scan.
General best practices for Dart development. Covers code style, effective Dart, and language features.
Best practices for validating Dart documentation comments. Covers using `dart doc` to catch unresolved references and macros.
Guidelines for handling long lines in Dart code to adhere to the 80-column rule. The `lines_longer_than_80_chars` lint.
Best practices for using `expect` and `package:matcher`. Focuses on readable assertions, proper matcher selection, and avoiding…
Guidelines for using modern Dart features (v3.0 - v3.10) such as Records, Extension Types, Class Modifiers, Wildcards, Digit…
Guidelines and best practices for refactoring consecutive prints, single-line string concatenations, and complex output blocks…