Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible not to add a new line before a single parameter when it's a collection? #1989

Closed
oleksii-suprun opened this issue May 28, 2020 · 2 comments · Fixed by #2000
Closed

Comments

@oleksii-suprun
Copy link

oleksii-suprun commented May 28, 2020

This template is a guideline, not a strict requirement.

  • Version: 2.5.3
  • Integration: IntelliJ
  • Configuration:
version = "2.5.3"
maxColumn = 120
align = none
project.git = true
runner.dialect = "Scala211"

includeNoParensInSelectChains = false

danglingParentheses.callSite = false

continuationIndent.defnSite = 2
continuationIndent.extendSite = 2
continuationIndent.withSiteRelativeToExtends = 2

newlines.implicitParamListModifierForce = [after]
newlines.afterCurlyLambda = squash
newlines.topLevelStatements = [before]
newlines.afterInfixBreakOnNested = true
newlines.source = keep
newlines.alwaysBeforeMultilineDef = false

rewrite.rules = [RedundantParens, SortModifiers, PreferCurlyFors, SortImports, RedundantBraces]
rewrite.redundantBraces.methodBodies = false
rewrite.redundantBraces.includeUnitMethods = true
rewrite.redundantBraces.stringInterpolation = true
rewrite.redundantBraces.generalExpressions = false
rewrite.sortModifiers.order = [
  "override", "private", "protected", "implicit", "final", "sealed", "abstract", "lazy"
]

verticalMultiline.atDefnSite = true
verticalMultiline.newlineAfterOpenParen = true
verticalMultiline.excludeDanglingParens = []

Steps

Given code like this:

      val schema = StructType(Seq(
        StructField("fieldA", DataTypes.StringType),
        StructField("fieldB", DataTypes.StringType)
      ))

When I run scalafmt like this:

scalafmt

Problem

Scalafmt formats code like this:

      val schema = StructType(
        Seq(
          StructField("fieldA", DataTypes.StringType),
          StructField("fieldB", DataTypes.StringType)
        ))

Expectation

I would like the formatted output to look like this:

      val schema = StructType(Seq(
        StructField("fieldA", DataTypes.StringType),
        StructField("fieldB", DataTypes.StringType)
      ))

Workaround

Not found. Looking for it.

Notes

I'm working a lot with Spark struct types. It's apply method takes a single collection parameter and I'd like to find a way to keep a collection type name on the same line with a StructType. Is there any possibility to do it?

@kitbellew
Copy link
Collaborator

please try newlines.source=fold.

@oleksii-suprun
Copy link
Author

oleksii-suprun commented May 28, 2020

I tried it, but unfortunately, newlines.source=fold is too "greedy" to me. It transforms the following piece:

      val schema = StructType(Seq(
        StructField("fieldA", DataTypes.StringType),
        StructField("fieldB", DataTypes.StringType)
      ))

into the following (single line):

    val schema =
      StructType(Seq(StructField("fieldA", DataTypes.StringType), StructField("fieldB", DataTypes.StringType)))

In my config I have newlines.source = keep and I'm satisfied with it in most cases. This is the only thing which I'd like to change and I was not sure that I did not miss some option which can help me. But this is not critical I can live with a current implementation if it's impossible to change it somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants