$npx -y skills add kevmoo/dash_skills --skill dart-best-practicesGeneral best practices for Dart development. Covers code style, effective Dart, and language features.
| 1 | # Dart Best Practices |
| 2 | |
| 3 | ## 1. When to use this skill |
| 4 | Use this skill when: |
| 5 | - Writing or reviewing Dart code. |
| 6 | - Looking for guidance on idiomatic Dart usage. |
| 7 | |
| 8 | ## 2. Best Practices |
| 9 | |
| 10 | ### Multi-line Strings |
| 11 | Prefer using multi-line strings (`'''`) over concatenating strings with `+` and |
| 12 | `\n`, especially for large blocks of text like SQL queries, HTML, or |
| 13 | PEM-encoded keys. This improves readability and avoids |
| 14 | `lines_longer_than_80_chars` lint errors by allowing natural line breaks. |
| 15 | |
| 16 | **Avoid:** |
| 17 | ```dart |
| 18 | final pem = '-----BEGIN RSA PRIVATE KEY-----\n' + |
| 19 | base64Encode(fullBytes) + |
| 20 | '\n-----END RSA PRIVATE KEY-----'; |
| 21 | ``` |
| 22 | |
| 23 | **Prefer:** |
| 24 | ```dart |
| 25 | final pem = ''' |
| 26 | -----BEGIN RSA PRIVATE KEY----- |
| 27 | ${base64Encode(fullBytes)} |
| 28 | -----END RSA PRIVATE KEY-----'''; |
| 29 | ``` |
| 30 | |
| 31 | ### Line Length |
| 32 | Avoid lines longer than 80 characters, even in Markdown files and comments. |
| 33 | This ensures code is readable in split-screen views and on smaller screens |
| 34 | without horizontal scrolling. |
| 35 | |
| 36 | **Prefer:** |
| 37 | Target 80 characters for wrapping text. Exceptions are allowed for long URLs |
| 38 | or identifiers that cannot be broken. |
| 39 | |
| 40 | ## Discovery |
| 41 | |
| 42 | ### Multi-line Strings |
| 43 | To find candidates for multi-line strings, search for string concatenation |
| 44 | with `+` involving newlines: |
| 45 | - **Regex**: `['"]\s*\+\s*['"]` |
| 46 | - **Regex**: `\+\s*['"].*\\n` |
| 47 | |
| 48 | ### Line Length |
| 49 | - Rely on the `lines_longer_than_80_chars` lint from the analyzer. |
| 50 | |
| 51 | ## Related Skills |
| 52 | |
| 53 | - **[dart-modern-features]**: For idiomatic |
| 54 | usage of modern Dart features like Pattern Matching (useful for deep JSON |
| 55 | extraction), Records, and Switch Expressions. |
| 56 | |
| 57 | [dart-modern-features]: https://github.com/kevmoo/dash_skills/blob/main/skills/dart-modern-features/SKILL.md |