Skip to content

Disable scalafmt docstring wrapping - #318

Merged
em3s merged 1 commit into
mainfrom
fix/scalafmt-docstring-wrap
May 11, 2026
Merged

em3s merged 1 commit into
mainfrom
fix/scalafmt-docstring-wrap

Conversation

@em3s

@em3s em3s commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Scalafmt 3.8.3 defaults docstrings.wrap = yes, which reflows the body of a /** ... */ block as if it were one paragraph and then hard-wraps it at maxColumn. For docstrings that intentionally use multi-line structure — numbered lists, step-by-step rules — this destroys the layout. Setting docstrings.wrap = no preserves the line breaks the author wrote, which is what every existing docstring in the repo already assumes.

Closes #

Changes

  • Add docstrings.wrap = no to .scalafmt.conf.
  • Add the same line to GenerateCodeStyleTask.generate() so that ./gradlew generateCodeStyle produces a matching file.
  • The other two docstring options (docstrings.style, docstrings.oneline) are already at sensible defaults, so only wrap needs to change.

Example

Author writes:

/**
 * Returns an iterator that batches events into groups.
 *
 * Grouping rules:
 * 1. Within a group, the same (a, b) key may not appear twice
 * 2. Group size must not exceed batchSize
 * 3. A repeated (a, b) key starts a new group
 * 4. Reaching batchSize closes the current group
 */

With the default (docstrings.wrap = yes), scalafmt rewrites this to:

/** Returns an iterator that batches events into groups.
  *
  * Grouping rules:
  *   1. Within a group, the same (a, b) key may not appear twice 2. Group size must not exceed batchSize 3. A repeated
  *      (a, b) key starts a new group 4. Reaching batchSize closes the current group
  */

The four numbered items are joined into one paragraph and the line is then hard-wrapped at maxColumn, leaving 1., 2., 3., 4. sitting side by side. With docstrings.wrap = no the original line structure is left alone.

How to Test

  • Drop the "author writes" snippet above into any Scala source file and run ./gradlew spotlessApply — the docstring should be left unchanged (modulo leading-asterisk style).
  • ./gradlew generateCodeStyle regenerates .scalafmt.conf and the docstrings.wrap = no line is present.

AI Assistance

  • This PR was written largely with AI assistance.
    • Tool / model: Claude Code (Opus 4.7)

With the default `docstrings.wrap = yes`, scalafmt reflows the contents
of `/** ... */` blocks as if they were one paragraph. A Korean docstring
with a four-item numbered list collapses into one line where items 1-4
sit side by side, and the line is then hard-wrapped at maxColumn,
producing nonsense indentation.

`docstrings.wrap = no` keeps the original line breaks inside the
docstring, which is what every existing docstring in the repo is
already written for. The other two docstring options (`docstrings.style`
and `docstrings.oneline`) are already at sensible defaults, so only
`wrap` needs to change.

The same line is added to `GenerateCodeStyleTask.generate()` so that
`./gradlew generateCodeStyle` produces a matching `scalafmt.conf`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. maintenance Maintenance work. labels May 11, 2026
@em3s
em3s merged commit ea5dacd into main May 11, 2026
3 checks passed
@em3s
em3s deleted the fix/scalafmt-docstring-wrap branch May 11, 2026 14:19
@em3s em3s self-assigned this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance work. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant