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

Feature: a one-liner version of newlines.alwaysBeforeElseAfterCurlyIf=true #1043

Closed
kitbellew opened this issue Sep 11, 2017 · 2 comments
Closed

Comments

@kitbellew
Copy link
Collaborator

This template is a guideline, not a strict requirement.

  • Version: 1.2.0
  • Integration: CLI
  • Configuration:
style = default
maxColumn = 100
danglingParentheses = true

align = none
align.tokens = []
align.openParenCallSite = false

newlines.alwaysBeforeTopLevelStatements = true
newlines.sometimesBeforeColonInMethodReturnType = false
newlines.alwaysBeforeCurlyBraceLambdaParams = true
newlines.afterImplicitKWInVerticalMultiline = true
newlines.beforeImplicitKWInVerticalMultiline = true

runner.fatalWarnings = true
runner.optimizer.forceConfigStyleOnOffset = 50
runner.optimizer.forceConfigStyleMinArgCount = 5

rewrite.rules = [ExpandImportSelectors, PreferCurlyFors]

Steps

I ran scalafmt like this:

scalafmt

Problem

Input is

      if ('0' <= ch && ch <= '9') { ch - '0' }
      else if ('A' <= ch && ch <= 'F') { ch - 'A' + 10 }
      else if ('a' <= ch && ch <= 'f') { ch - 'a' + 10 }
      else { -1 }

Scalafmt formats code like this:

      if ('0' <= ch && ch <= '9') { ch - '0' } else if ('A' <= ch && ch <= 'F') { ch - 'A' + 10 } else if ('a' <= ch && ch <= 'f') {
        ch - 'a' + 10
      } else { -1 }

Expectation

I would like the formatted output to look either exactly like the input, or like this:

      if ('0' <= ch && ch <= '9') {
        ch - '0'
      } else if ('A' <= ch && ch <= 'F') {
        ch - 'A' + 10
      } else if ('a' <= ch && ch <= 'f') {
        ch - 'a' + 10
      } else {
        -1
      }

but definitely not the way it was chosen.

@olafurpg
Copy link
Member

Thanks for reporting! This is a duplicate of #271, I agree the formatted output is not good.

Note that when given

    if ('0' <= ch && ch <= '9') {
        ch - '0'
      } else if ('A' <= ch && ch <= 'F') {
        ch - 'A' + 10
      } else if ('a' <= ch && ch <= 'f') {
        ch - 'a' + 10
      } else {
        -1
      }

Scalafmt leaves the code unchanged.

olafurpg added a commit to olafurpg/scalafmt that referenced this issue May 13, 2018
@olafurpg
Copy link
Member

FYI I opened #1180 forcing a line break for if/else bodies that are blocks so that the formatted output matches expected output in this ticket. No need to manually insert line breaks :)

kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 8, 2020
While previously we were trying to keep blocks without line breaks if
that's how they were originally input, now we actively attempt to take a
multi-line representation and fold it into a single line (fold), or take
a single-line representation and unfold it into multiple lines (unfold).

Fixes scalameta#271 scalameta#1002 scalameta#1043
Helps with scalameta#1627
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 9, 2020
While previously we were trying to keep blocks without line breaks if
that's how they were originally input, now we actively attempt to take a
multi-line representation and fold it into a single line (fold), or take
a single-line representation and unfold it into multiple lines (unfold).

Fixes scalameta#271 scalameta#1002 scalameta#1043
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 9, 2020
While previously we were trying to keep blocks without line breaks if
that's how they were originally input, now we actively attempt to take a
multi-line representation and fold it into a single line (fold), or take
a single-line representation and unfold it into multiple lines (unfold).

Fixes scalameta#271 scalameta#1002 scalameta#1043
kitbellew added a commit to kitbellew/scalafmt that referenced this issue Mar 9, 2020
While previously we were trying to keep blocks without line breaks if
that's how they were originally input, now we actively attempt to take a
multi-line representation and fold it into a single line (fold), or take
a single-line representation and unfold it into multiple lines (unfold).

Fixes scalameta#271 scalameta#1002 scalameta#1043
kitbellew added a commit that referenced this issue Mar 9, 2020
While previously we were trying to keep blocks without line breaks if
that's how they were originally input, now we actively attempt to take a
multi-line representation and fold it into a single line (fold), or take
a single-line representation and unfold it into multiple lines (unfold).

Fixes #271 #1002 #1043
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

No branches or pull requests

2 participants