Skip to content

Commit

Permalink
Router: fix indent after yield w/ NL+comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 30, 2024
1 parent d9b7ef5 commit 7ce27ee
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2308,8 +2308,7 @@ class Router(formatOps: FormatOps) {
val lastToken = getLastToken(leftOwner.asInstanceOf[Term.ForYield].body)
val indent = Indent(style.indent.main, lastToken, ExpiresOn.After)
if (style.newlines.avoidAfterYield && !rightOwner.is[Term.If]) {
val nextFt = nextNonCommentSameLine(ft)
val noIndent = nextFt.eq(ft) || nextFt.noBreak
val noIndent = !isRightCommentWithBreak(ft)
Seq(Split(Space, 0).withIndent(indent, noIndent))
} else Seq(
// Either everything fits in one line or break on =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9718,20 +9718,20 @@ class ClassEmitter {
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
// 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
}

}
20 changes: 10 additions & 10 deletions scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9117,16 +9117,16 @@ class ClassEmitter {
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
// 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
}

}
30 changes: 15 additions & 15 deletions scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -9515,21 +9515,21 @@ class ClassEmitter {
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
// 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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9797,16 +9797,16 @@ class ClassEmitter {
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
// 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 7ce27ee

Please sign in to comment.