Skip to content

Commit 94e44e7

Browse files
committed
Addressed issues mentioned in the code review
1 parent cb47518 commit 94e44e7

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

readme/Configuration.scalatex

+14
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,20 @@
771771
while(a) foo()
772772
for(a <- as) foo()
773773

774+
@sect{spaces.afterSymbolicDefs}
775+
Default: @b(default.spaces.afterSymbolicDefs)
776+
777+
@hl.scala
778+
// spaces.afterSymbolicDefs = true
779+
trait Test[A] {
780+
def <=> [B](that: Test[B]): Int
781+
}
782+
783+
// spaces.afterSymbolicDefs = false
784+
trait Test[A] {
785+
def <=>[B](that: Test[B]): Int
786+
}
787+
774788
@sect{includeCurlyBraceInSelectChains}
775789
Default: @b(default.includeCurlyBraceInSelectChains)
776790

scalafmt-core/shared/src/main/scala/org/scalafmt/config/Spaces.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import org.scalafmt.config.SpaceBeforeContextBound.Never
2121
* @param inByNameTypes
2222
* If false, removes space in by-name parameter.
2323
* `def foo(a: =>A)`
24+
* @param afterSymbolicDefs If true, adds a single space after an operator method
25+
* For example:
26+
* def <=> [T](that: T): Boolean
2427
*/
2528
case class Spaces(
2629
beforeContextBoundColon: SpaceBeforeContextBound = Never,
@@ -29,7 +32,8 @@ case class Spaces(
2932
inParentheses: Boolean = false,
3033
neverAroundInfixTypes: Seq[String] = Nil,
3134
afterKeywordBeforeParen: Boolean = true,
32-
inByNameTypes: Boolean = true
35+
inByNameTypes: Boolean = true,
36+
afterSymbolicDefs: Boolean = true
3337
) {
3438
implicit val reader: ConfDecoder[Spaces] = generic.deriveDecoder(this).noTypos
3539
}

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import org.scalafmt.util.TokenOps
3737
import org.scalafmt.util.TreeOps
3838
import org.scalafmt.util.Trivia
3939

40-
import scala.meta.Decl.Def
4140
import scala.meta.Lit
4241

4342
// Too many to import individually.
@@ -75,7 +74,6 @@ class Router(formatOps: FormatOps) {
7574
val leftOwner = owners(formatToken.left)
7675
val rightOwner = owners(formatToken.right)
7776
val newlines = newlinesBetween(formatToken.between)
78-
val isDef = rightOwner.tokens.headOption.exists(_.is[KwDef])
7977

8078
formatToken match {
8179
case FormatToken(_: BOF, _, _) =>
@@ -359,10 +357,10 @@ class Router(formatOps: FormatOps) {
359357
// Opening [ with no leading space.
360358
// Opening ( with no leading space.
361359
case FormatToken(
362-
KwSuper() | KwThis() | Ident(_) | RightBracket() | RightBrace() |
363-
RightParen() | Underscore(),
364-
LeftParen() | LeftBracket(),
365-
_) if noSpaceBeforeOpeningParen(rightOwner) && {
360+
KwSuper() | KwThis() | Ident(_) | RightBracket() | RightBrace() |
361+
RightParen() | Underscore(),
362+
LeftParen() | LeftBracket(),
363+
_) if noSpaceBeforeOpeningParen(rightOwner) && {
366364
leftOwner.parent.forall {
367365
// infix applications have no space.
368366
case _: Type.ApplyInfix | _: Term.ApplyInfix => false
@@ -375,7 +373,8 @@ class Router(formatOps: FormatOps) {
375373
if style.spaces.afterTripleEquals &&
376374
t.tokens.map(_.syntax) == Seq("===") =>
377375
Space
378-
case name: Term.Name if isDef && isSymbolicName(name.value) =>
376+
case name: Term.Name
377+
if isSymbolicName(name.value) && name.parent.exists(isDefDef) =>
379378
Space
380379
case _ => NoSplit
381380
}

scalafmt-tests/src/test/resources/unit/UnaryApply.stat

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
<<< #697 you shall not change AST!!
2828
def =!=(that: S): Boolean = ! ===(that)
2929
>>>
30-
def =!=(that: S): Boolean = ! ===(that)
30+
def =!= (that: S): Boolean =
31+
! ===(that)
3132
<<< #710 you shall not add unneeded space!!
3233
if (!_member) Some(x) else None
3334
>>>

0 commit comments

Comments
 (0)