Skip to main content
skill CX Codex

dart-multiline-strings — Claude Code skill: Dart string refactoring

dart-multiline-strings — a skill for Claude Code, Codex, Cursor and other agents that teaches rewriting consecutive print() calls and string concatenations into triple-quoted literals (''' or """).

Apache-2.0 116 installs ★ 149 updated 2026-10-17

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add kevmoo/dash_skills --skill dart-multiline-strings -a claude-code
Open on GitHub

What dart-multiline-strings does

The skill gives the agent a set of detection rules for refactoring candidates: back-to-back print() or stdout.writeln() calls, strings packed with \n escapes, and concatenations using +.

The skill also defines when to leave strings alone — single-line outputs under 80 characters, strings pulled from localization bundles (intl, ARB files), protocol strings where indentation whitespace changes payload meaning, and streaming output like progress bars or spinners. Without those guardrails, an agent could rewrite code that must not change.

On top of that, the skill covers Dart 3 switch expressions inside interpolations, ghost blank-line prevention when using ${condition ? '...' : ''}, and correct placement of closing ''' so print() does not append an unexpected trailing blank line. The lines_longer_than_80_chars lint rule is automatically suppressed inside multiline string literals, and the skill accounts for that.

What it helps with

  • Merge a series of print() statements into one triple-quoted block
  • Strip \n escapes from long single-line strings
  • Format CLI help text or templated messages as readable literals
  • Inject conditional output via a switch expression without extra if-blocks
  • Prevent accidental trailing blank lines caused by misplaced closing ''

Example prompts for the agent

  • Rewrite all consecutive print() calls in printGerritView using triple-quoted strings
  • Convert the \n-heavy strings in this file to ''' literals and remove empty print('') separators
  • Refactor this conditional output block to use a switch expression inside string interpolation with no ghost blank lines

How to install dart-multiline-strings

1Skills CLI (Vercel)

npx skills add kevmoo/dash_skills --skill dart-multiline-strings -a claude-code

2Manually: put the files in place

~/.claude/skills/dart-multiline-strings/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dart-multiline-strings/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dart-multiline-strings

How do I install dart-multiline-strings in Claude Code?

Run npx skills add kevmoo/dash_skills --skill dart-multiline-strings -a claude-code. The skill file will be placed at ~/.claude/skills/dart-multiline-strings/SKILL.md.

What does the dart-multiline-strings skill do?

It gives the agent rules for Dart string refactoring: when to replace print() chains, + concatenations, and \n-heavy strings with triple-quoted literals, and when to leave the code as is.

When does the skill tell the agent not to refactor?

The agent skips strings from localization catalogs (intl, ARB), protocol strings where internal whitespace carries meaning, and any streaming or incremental I/O like spinners or progress bars.

Source text

SKILL.md · Apache-2.0
---
name: dart-multiline-strings
description: |-
  Guidelines and best practices for refactoring consecutive prints, single-line
  string concatenations, and complex output blocks into triple-quoted multi-line
  string literals (''' or """) in Dart.
license: Apache-2.0
key_features:
  - Triple-quoted multiline strings
  - Print & concatenation refactoring
  - Formatting large text blocks
---

# Dart Multi-line Strings

## 1. When to use this skill

Use this skill when:

- Refactoring consecutive `print()` or `stdout.writeln()` statements into a
  single, cohesive output block.
- Simplifying string literals that span multiple lines, contain embedded
  newlines (`\n`), or use nested indentations.
- Formatting large user-facing text output (like CLI help menus, reports, or
  templated messages) to be readable, maintainable, and performant.

### When NOT to use (Abstention Guardrails)

Do NOT refactor to multiline strings when:

- **Short, Single-Line Outputs**: Strings that comfortably fit on a single line
  (<80 chars) without embedded newlines.
- **Localized String Catalogs**: Strings that are looked up from localization
  bundles (e.g. `intl`, ARB files), where line breaks or formatting must conform
  to external translation tooling.
- **Raw Query Strings with Strict Whitespace Semantics**: Protocol strings,
  strict CSV rows, or queries where indentation whitespace inside triple quotes
  would alter payload semantics or introduce unintended leading spaces.
- **Streaming or Incremental I/O**: Progress bars, spinners, or interactive
  console streams where individual writes occur with delays or flushing between
  lines.

## Discovery

To find candidate code blocks for multi-line string refactoring:

- Look for multiple back-to-back `print()` or `stdout.writeln()` calls inside a
  function, especially inside loops, console views, or CLI controllers.
- Look for single-line strings heavily loaded with `\n` escape sequences.
- Look for multiple string concatenations using the `+` operator or adjacent
  string literal splits that are meant to represent multi-line outputs.

## 2. Guidelines

### Combine Consecutive Outputs

Instead of calling `print()` repeatedly for a multi-line output, group the
contents into a single triple-quoted string literal: `print('''...''')`.

### Explicit and Clean Alignment

In a triple-quoted literal, the exact spacing and formatting inside the quotes
are preserved. Use this to specify indentation levels visually instead of using
manually padded space prefixes (e.g., `'    '`).

### Remove Empty Print Calls

If there are empty `print()` or `print('')` statements serving as vertical
separators between output segments, replace them by letting the trailing newline
of a multi-line string block handle the separation naturally.

### Handling the First Newline

If the opening triple-quote is immediately followed by a newline, the compiler
discards it.

- If you do **not** want a leading blank line, start the string content on a
  fresh line in the source code for clean layout.
- If you **do** want a leading blank line in the output, leave an extra empty
  line inside the triple-quoted block, or use `\n` explicitly at the beginning:
  ```dart
  print('''

  This starts with one blank line above it.''');
  ```

### Handling the Trailing Newline & `print()`

`print()` automatically appends a trailing newline to the printed output.

- If you place the closing `'''` on a new line (`\n''');`), an extra trailing
  blank line will be printed.
- To avoid unintended trailing blank lines, place the closing triple-quotes
  immediately after the final character:
  ```dart
  // ✅ Emits standard output with no extra trailing empty line:
  print('''
  Header
  Content''');
  ```

### Avoiding Ghost Blank Lines in Conditional Interpolations

When injecting optional content via interpolation (`${condition ? '...' : ''}`),
placing the `${...}` on its own line leaves behind its enclosing newline when
the condition evaluates to `''`, producing an empty blank line in the output.

- Include the leading newline _inside_ the conditional string literal so the
  newline only renders when the content is present:
  ```dart
  // ✅ Clean conditional rendering without ghost blank lines:
  print('''
  Branch Details:
      Name: $branch${hasWarning ? '\n    WARNING: $warningMessage' : ''}''');
  ```

### 80-Character Line Limit Exemption

The `lines_longer_than_80_chars` lint rule **automatically ignores** lines
inside multiline string literals. You can write long lines inside triple-quotes
without triggering linter warnings or being forced to break them up.

### Dynamic Switch Expressions inside Interpolation

Leverage Dart 3 switch expressions directly inside string interpolations to
dynamically select and inject optional lines, conditional labels, or helper
instructions. This avoids cluttering the surrounding code with imperatively
constructed strings or multiple `if` statements:

```dart
print('''
Status: ${status.isSuccess ? 'PASS' : 'FAIL'}${switch (status) {
  Status.failed => '\nError details: $errorMessage',
  _ => '',
}}''');
```

## 3. Examples

### Refactoring Consecutive Prints with Indentation

**Avoid:**

```dart
void printGerritView(String branch, String desc, bool hasConflicts) {
  print('Branch Details:');
  print('    Name:        ' + branch);
  print('    Description: ' + desc);
  print('');
  if (hasConflicts) {
    print('    WARNING: This branch has conflicts.');
    print('    Run `git merge origin/main` to resolve.');
  }
}
```

**Prefer:**

```dart
void printGerritView(String branch, String desc, bool hasConflicts) {
  print('''
Branch Details:
    Name:        $branch
    Description: $desc${hasConflicts ? '''

    WARNING: This branch has conflicts.
    Run `git merge origin/main` to resolve.''' : ''}''');
}
```

© kevmoo · Apache-2.0 · kevmoo/dash_skills

Similar skills

All skills for Programming languages →

From the same set9

dart-best-practices dart-best-practices enforces idiomatic Dart code style and formatting during generation and review. Focuses on clean multi-line string literals and strict 80-character line wrapping. CX Codex +1 847installs dart-test-fundamentals dart-test-fundamentals — a skill for Claude Code and Codex that enforces best practices for Dart's package:test. It structures test suites, configures dart_test.yaml, and handles teardowns. CX Codex +1 455installs dart-modern-features dart-modern-features guides coding agents on modern Dart 3.0 to 3.10 features. It helps adopt records, extension types, class modifiers, and null-aware elements during refactoring. CX Codex +1 370installs dart-doc-validation The dart-doc-validation skill for Claude Code validates Dart documentation comments with dart doc and the comment_references lint, catching broken links. CX Codex +1 291installs dart-package-maintenance dart-package-maintenance — a skill for maintaining Dart packages per Dart team standards: manage semantic versioning, keep CHANGELOG in sync, and prepare releases. Essential if you publish packages to pub.dev. CX Codex +1 285installs dart-matcher-best-practices dart-matcher-best-practices is a Claude Code skill for writing Dart tests with expect and package:matcher. It steps in when adding assertions, cleaning up manual checks, or investigating confusing test failures. CX Codex +1 269installs dart-test-coverage Run Dart test coverage, inspect missed lines, and identify code that needs tests. Useful when checking which parts of a package remain untested. CX Codex +1 163installs dart-long-lines dart-long-lines is a Claude Code skill for keeping Dart lines within 80 columns. It applies while writing code or fixing the lines_longer_than_80_chars lint. CX Codex +1 150installs

Project sponsors

Companies that keep this analytics open