Skip to content

Commit

Permalink
FormatOps: no blank within infix if not enclosed
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 30, 2024
1 parent a56de87 commit d9b7ef5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,10 @@ class FormatOps(
rtidx >= 0 && (atokens(rtidx) eq ft.right) // no rewritten tokens
}
}
val useSpace = ft.noBreak || !okToBreak
val split = Split(if (useSpace) spaceMod else Newline2x(ft), 0)
val mod =
if (ft.noBreak || !okToBreak) spaceMod
else Newline2x(isFullInfixEnclosed && ft.hasBlankLine)
val split = Split(mod, 0)
if (isBeforeOp && isFewerBracesRhs(app.arg)) Seq(split)
else Seq(InfixSplits.withNLIndent(split, app, fullInfix))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9710,22 +9710,28 @@ class ClassEmitter {

}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
chainProto :::
- (
- genIdentBracketSelect(
- prototypeFor(ctorVar),
- "constructor"
- ) := ctorVar
- ) ::
+ (genIdentBracketSelect(
+ prototypeFor(ctorVar),
+ "constructor"
+ ) := ctorVar) ::
- // Inheritable constructor
- js.JSDocConstructor(inheritableCtorDef.head) ::
+ // Inheritable constructor
+ js.JSDocConstructor(inheritableCtorDef.head) ::
inheritableCtorDef.tail :::
class ClassEmitter {

def genScalaClassConstructor =

if (useESClass) {
for {
chainProto <- chainProtoWithGlobals
} yield
// Real constructor
js.JSDocConstructor(realCtorDef.head) ::
realCtorDef.tail :::
chainProto :::
(genIdentBracketSelect(
prototypeFor(ctorVar),
"constructor"
) := ctorVar) ::
// Inheritable constructor
js.JSDocConstructor(inheritableCtorDef.head) ::
inheritableCtorDef.tail :::
(globalVar(VarField.h, className).prototype := prototypeFor(
ctorVar
)) :: Nil
}

}
34 changes: 26 additions & 8 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9507,11 +9507,29 @@ class ClassEmitter {

}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
- // Inheritable constructor
- js.JSDocConstructor(inheritableCtorDef.head) ::
+ // Inheritable constructor
+ js.JSDocConstructor(inheritableCtorDef.head) ::
inheritableCtorDef.tail :::
class ClassEmitter {

def genScalaClassConstructor =

if (useESClass) {
for {
chainProto <- chainProtoWithGlobals
} yield
// Real constructor
js.JSDocConstructor(realCtorDef.head) ::
realCtorDef.tail :::
chainProto :::
(genIdentBracketSelect(
prototypeFor(ctorVar),
"constructor"
) := ctorVar) ::
// Inheritable constructor
js.JSDocConstructor(inheritableCtorDef.head) ::
inheritableCtorDef.tail :::
(globalVar(
VarField.h,
className
).prototype := prototypeFor(ctorVar)) :: Nil
}

}

0 comments on commit d9b7ef5

Please sign in to comment.