Skip to content

Enforce Javadoc-style docstrings in scalafmt - #319

Merged
em3s merged 1 commit into
mainfrom
refactor/scalafmt-javadoc-docstring
May 12, 2026
Merged

em3s merged 1 commit into
mainfrom
refactor/scalafmt-javadoc-docstring

Conversation

@em3s

@em3s em3s commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Force scalafmt to keep the opening /** on its own line so Scala docstrings match the Javadoc layout that the Java and Kotlin code in this repo already use. With the scalafmt default, the first line of the docstring is folded onto /**, producing the Scaladoc one-line shape that looks foreign next to the rest of the codebase.

Closes #

Changes

  • Add docstrings.blankFirstLine = yes to .scalafmt.conf.
  • Add the same line to GenerateCodeStyleTask.generate() so ./gradlew generateCodeStyle produces a matching file.

Example

Author writes:

/**
 * Some doc.
 *
 * More details.
 */

Default scalafmt rewrites this to:

/** Some doc.
  *
  * More details.
  */

With docstrings.blankFirstLine = yes:

/**
  * Some doc.
  *
  * More details.
  */

The leading-asterisk style ( *) is left at the scalafmt default; only the first line is forced to be blank, which is the single switch that flips Scaladoc-shape into Javadoc-shape.

How to Test

  • ./gradlew generateCodeStyle regenerates .scalafmt.conf with the docstrings.blankFirstLine = yes line present.
  • Drop the "author writes" snippet into a Scala source file and run ./gradlew spotlessApply — the opening /** should stay on its own line.

AI Assistance

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

Scalafmt default folds the first line of a docstring onto the opening
`/**`, producing the Scaladoc one-line shape:

    /** Some doc.
      *
      * More details.
      */

Setting `docstrings.blankFirstLine = yes` forces the opening `/**` onto
its own line, matching the Javadoc style that the rest of the codebase
(Java and Kotlin) already uses:

    /**
      * Some doc.
      *
      * More details.
      */

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 175e00b into main May 12, 2026
3 checks passed
@em3s
em3s deleted the refactor/scalafmt-javadoc-docstring branch May 12, 2026 01:55
@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