Skip to content

Commit

Permalink
ScalafmtConfig: fix withoutRewrites docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Oct 3, 2023
1 parent 84c9f26 commit 24edfdc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ case class Docstrings(
) {
import Docstrings._

def withoutRewrites: Docstrings =
copy(removeEmpty = false, wrap = Wrap.no, style = Preserve)

def skipFirstLineIf(wasBlank: Boolean): Boolean = blankFirstLine match {
case BlankFirstLine.yes => true
case BlankFirstLine.no => style.skipFirstLine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ case class ScalafmtConfig(
// used in ScalafmtReflectConfig
def withoutRewrites: ScalafmtConfig = copy(
trailingCommas = None,
docstrings = docstrings.withoutRewrites,
rewrite = rewrite.withoutRewrites
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ class FormatWriter(formatOps: FormatOps) {
val codeStyle = style.copy(
runner = style.runner.forCodeBlock,
// let's not wrap docstrings, to avoid recursion
docstrings = style.docstrings.copy(wrap = Docstrings.Wrap.no),
docstrings = style.docstrings.withoutRewrites,
maxColumn = style.maxColumn - spaces.length - termIndent.length - 1
)
Scalafmt.format(code.mkString("\n"), codeStyle) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ScalafmtConfigTest extends FunSuite {
.get
assert(config1.hasRewrites)
val config2 = config1.withoutRewrites
assert(config2.hasRewrites) // XXX: this is incorrect
assert(!config2.hasRewrites)
}

}

0 comments on commit 24edfdc

Please sign in to comment.