Dart 长行代码规范处理
dart-long-lines
处理 Dart 代码中长行以遵守 80 列规则的指南,即 `lines_longer_than_80_chars` lint 检查。
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 8
- Forks
- 7
01 前言 Front Matter
- name
- dart-long-lines
- license
- Apache-2.0
- description
- Guidelines for handling long lines in Dart code to adhere to the 80-column rule. The `lines_longer_than_80_chars` lint.
- key_features
- [ "80-column rule compliance", "Line length refactoring", "Linter rule enforcement" ]
02 资源文件 1
- 参考文档evals/evals.json2.2 KB
03 SKILL.md 正文
Dart Long Lines
1. When to use this skill
Use this skill when:
- Writing Dart code that might exceed the 80-column limit.
- Refactoring code to comply with the
lines_longer_than_80_charslint. Reference: https://dart.dev/tools/linter-rules/lines_longer_than_80_chars
When NOT to use (Abstention Guardrails)
Do NOT break lines or alter code when:
- Unbreakable URLs & URIs: Lines contain long HTTP/HTTPS URLs, import URIs, or file paths where breaking them across lines would invalidate the link.
- Complex Regular Expression Literals: Long RegExp patterns
(
RegExp(r'...')) where inserting whitespace or line breaks changes the matching semantics. - ASCII Art, Tables, or Preformatted Diagrams: Preformatted text blocks, table rows, or ASCII diagrams inside comments or strings where wrapping lines destroys visual alignment.
- Prior to Automated Formatting: Do NOT manually break code lines before
running
dart format. Letdart formathandle code wrapping automatically; only manually wrap comments, docs, and multi-line strings that the formatter does not re-wrap.
Discovery
To find lines that exceed the limit:
Automated Analysis
The most reliable way to find long lines is to use the Dart analyzer:
- Command:
dart analyze - Lint:
lines_longer_than_80_chars
Manual Search
To search for long lines using regex:
- Regex:
^.{81,}$(Matches any line with 81 or more characters).
2. Guidelines
Format First
Always run dart format before manually breaking long lines. The formatter
often automatically fixes long lines, especially in generated code, and applies
standard Dart styling rules.
Code Comments
Break long code comments (//) cleanly at word boundaries to ensure lines do
not exceed 80 characters. Maintain tight formatting and avoid unnecessary
vertical space.
Documentation Comments (///)
- Apply the same line-breaking rules as for code comments.
- Avoid breaking markdown link blocks like
[name]or[text](http://example.com)across lines. Place them on their own line if they exceed the limit. - Start doc comments with a single summary sentence, followed by a blank line before the rest of the comment. It is okay to break this first sentence across multiple lines to fit the 80-column limit.
- Avoid unresolved references or dangling sentences.
Long Strings
- Use adjacent string literals (e.g.,
'part 1 ' 'part 2') to break long strings. Break at word boundaries. - If a single-line string contains newline characters (
\n) or if there are consecutiveprintstatements, consider migrating to a multi-line string literal (''').
Format and Analyze After Changes
- Run
dart formatanddart analyzeafter making changes. - Be aware that splitting strings may trigger new lints (e.g.,
prefer_single_quotesif a double-quoted string is split into parts that no longer contain single quotes).
3. Examples
Documentation Comment Link
Avoid:
/// This is a long doc comment that contains a link to [a very long
/// URL](http://example.com/very/long/url/that/exceeds/eighty/chars).
Prefer:
/// This is a long doc comment that contains a link to [a very long URL][ref].
///
/// [ref]: http://example.com/very/long/url/that/exceeds/eighty/chars
Adjacent String Literals
Prefer:
final longString = 'This is a very long string that needs to be broken '
'across multiple lines to stay under the limit.';
Multi-line String Migration
Avoid:
print('This is line 1\nThis is line 2 that is also quite long\nThis is line 3 which makes the whole thing exceed eighty characters');
Prefer:
print('''This is line 1
This is line 2 that is also quite long
This is line 3 which makes the whole thing exceed eighty characters''');
04 同仓库更多 Skills
Dart 单元测试基础
dart-test-fundamentals
`package:test` 的核心概念与最佳实践。 涵盖 `test`、`group`、生命周期方法(`setUp`、`tearDown`)以及配置(`dart_test.yaml`)。
Dart 断言匹配器最佳实践
dart-matcher-best-practices
使用 `expect` 和 `package:matcher` 的最佳实践。 重点关注可读的断言、正确选择匹配器以及避免常见陷阱。
Dart 文档注释校验
dart-doc-validation
验证 Dart 文档注释的最佳实践。涵盖使用 `dart doc` 检测未解析的引用和宏。
Dart 开发最佳实践
dart-best-practices
Dart 开发的通用最佳实践。涵盖代码风格、Effective Dart(有效的 Dart)和语言特性。
GitHub Issue 分类与整理
triage-github-issues
按类型和优先级对新的 GitHub issue 进行分类,询问缺失的详细信息,并关闭重复项。当被要求对 issue tracker 进行分类(triage)、添加标签或清理时使用。
Dart 包版本发布
release-dart-package
准备并将 Dart 包的新版本发布到 pub.dev,涵盖从版本号提升到 GitHub release 的完整流程。当被要求创建(cut)、打标签(tag)或发布(publish)版本时使用。