$npx -y skills add kevmoo/dash_skills --skill dart-long-linesGuidelines for handling long lines in Dart code to adhere to the 80-column rule. The lines_longer_than_80_chars lint.
| 1 | # Dart Long Lines |
| 2 | |
| 3 | ## 1. When to use this skill |
| 4 | |
| 5 | Use this skill when: |
| 6 | - Writing Dart code that might exceed the 80-column limit. |
| 7 | - Refactoring code to comply with the `lines_longer_than_80_chars` lint. |
| 8 | Reference: https://dart.dev/tools/linter-rules/lines_longer_than_80_chars |
| 9 | |
| 10 | ## Discovery |
| 11 | |
| 12 | To find lines that exceed the limit: |
| 13 | |
| 14 | ### Automated Analysis |
| 15 | The most reliable way to find long lines is to use the Dart analyzer: |
| 16 | - **Command**: `dart analyze` |
| 17 | - **Lint**: `lines_longer_than_80_chars` |
| 18 | |
| 19 | ### Manual Search |
| 20 | To search for long lines using regex: |
| 21 | - **Regex**: `^.{81,}$` (Matches any line with 81 or more characters). |
| 22 | |
| 23 | ## 2. Guidelines |
| 24 | |
| 25 | ### Format First |
| 26 | Always run `dart format` before manually breaking long lines. The formatter |
| 27 | often automatically fixes long lines, especially in generated code, and |
| 28 | applies standard Dart styling rules. |
| 29 | |
| 30 | ### Code Comments |
| 31 | Break long code comments (`//`) cleanly at word boundaries to ensure lines do |
| 32 | not exceed 80 characters. Maintain tight formatting and avoid unnecessary |
| 33 | vertical space. |
| 34 | |
| 35 | ### Documentation Comments (`///`) |
| 36 | - Apply the same line-breaking rules as for code comments. |
| 37 | - Avoid breaking markdown link blocks like `[name]` or |
| 38 | `[text](http://example.com)` across lines. Place them on their own line if |
| 39 | they exceed the limit. |
| 40 | - Start doc comments with a single summary sentence, followed by a blank line |
| 41 | before the rest of the comment. It is okay to break this first sentence |
| 42 | across multiple lines to fit the 80-column limit. |
| 43 | - Avoid unresolved references or dangling sentences. |
| 44 | |
| 45 | ### Long Strings |
| 46 | - Use adjacent string literals (e.g., `'part 1 ' 'part 2'`) to break long |
| 47 | strings. Break at word boundaries. |
| 48 | - If a single-line string contains newline characters (`\n`) or if there are |
| 49 | consecutive `print` statements, consider migrating to a multi-line string |
| 50 | literal (`'''`). |
| 51 | |
| 52 | ### Format and Analyze After Changes |
| 53 | - Run `dart format` and `dart analyze` after making changes. |
| 54 | - Be aware that splitting strings may trigger new lints (e.g., |
| 55 | `prefer_single_quotes` if a double-quoted string is split into parts that |
| 56 | no longer contain single quotes). |
| 57 | |
| 58 | ## 3. Examples |
| 59 | |
| 60 | ### Documentation Comment Link |
| 61 | **Avoid:** |
| 62 | ```dart |
| 63 | /// This is a long doc comment that contains a link to [a very long |
| 64 | /// URL](http://example.com/very/long/url/that/exceeds/eighty/chars). |
| 65 | ``` |
| 66 | |
| 67 | **Prefer:** |
| 68 | ```dart |
| 69 | /// This is a long doc comment that contains a link to [a very long URL][ref]. |
| 70 | /// |
| 71 | /// [ref]: http://example.com/very/long/url/that/exceeds/eighty/chars |
| 72 | ``` |
| 73 | |
| 74 | ### Adjacent String Literals |
| 75 | **Prefer:** |
| 76 | ```dart |
| 77 | final longString = 'This is a very long string that needs to be broken ' |
| 78 | 'across multiple lines to stay under the limit.'; |
| 79 | ``` |
| 80 | |
| 81 | ### Multi-line String Migration |
| 82 | **Avoid:** |
| 83 | ```dart |
| 84 | 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'); |
| 85 | ``` |
| 86 | |
| 87 | **Prefer:** |
| 88 | ```dart |
| 89 | print('''This is line 1 |
| 90 | This is line 2 that is also quite long |
| 91 | This is line 3 which makes the whole thing exceed eighty characters'''); |
| 92 | ``` |