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

Non-idempotent formatting with multiline string in annotation #1640

Closed
steinybot opened this issue Jan 19, 2020 · 2 comments · Fixed by #2009
Closed

Non-idempotent formatting with multiline string in annotation #1640

steinybot opened this issue Jan 19, 2020 · 2 comments · Fixed by #2009
Assignees
Labels

Comments

@steinybot
Copy link

steinybot commented Jan 19, 2020

This template is a guideline, not a strict requirement.

  • Version: 2.3.0
  • Integration: IntelliJ
  • Configuration:
version = "2.3.0"

assumeStandardLibraryStripMargin = true
maxColumn = 120
rewrite.rules = [
  SortModifiers
]

Steps

Given code like this:

import scala.annotation.implicitNotFound

@implicitNotFound("""Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
                    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin)
trait Show[T, P, R]

When I run scalafmt like this:

sbt:bug-reports> clean
[success] Total time: 0 s, completed 20/01/2020, 11:35:50 am
sbt:bug-reports> scalafmtCheck
[info] Checking 1 Scala sources...
[warn] /Users/jason/source/bug-reports/src/main/scala/Show.scala isn't formatted properly!
[error] 1 files must be formatted
[error] (Compile / scalafmtCheck) 1 files must be formatted
[error] Total time: 0 s, completed 20/01/2020, 11:35:55 am
sbt:bug-reports> scalafmt
[info] Formatting 1 Scala sources...
[success] Total time: 0 s, completed 20/01/2020, 11:36:01 am
sbt:bug-reports> scalafmtCheck
[success] Total time: 0 s, completed 20/01/2020, 11:36:09 am
sbt:bug-reports> clean
[success] Total time: 0 s, completed 20/01/2020, 11:36:13 am
sbt:bug-reports> scalafmtCheck
[info] Checking 1 Scala sources...
[warn] /Users/jason/source/bug-reports/src/main/scala/Show.scala isn't formatted properly!
[error] 1 files must be formatted
[error] (Compile / scalafmtCheck) 1 files must be formatted
[error] Total time: 0 s, completed 20/01/2020, 11:36:16 am
sbt:bug-reports> scalafmt
[info] Formatting 1 Scala sources...
[success] Total time: 0 s, completed 20/01/2020, 11:36:22 am
sbt:bug-reports> scalafmtCheck
[success] Total time: 0 s, completed 20/01/2020, 11:36:27 am
sbt:bug-reports> clean
[success] Total time: 0 s, completed 20/01/2020, 11:39:53 am
sbt:bug-reports> scalafmtCheck
[info] Checking 1 Scala sources...
[warn] /Users/jason/source/bug-reports/src/main/scala/Show.scala isn't formatted properly!
[error] 1 files must be formatted
[error] (Compile / scalafmtCheck) 1 files must be formatted
[error] Total time: 0 s, completed 20/01/2020, 11:39:56 am

Problem

Scalafmt formats code like this:

import scala.annotation.implicitNotFound

@implicitNotFound(
  """Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin
)
trait Show[T, P, R]

Which then checks ok until sbt clean is run and then it fails again. Doing another scalafmt causes it to go back to the original and again after sbt clean it will fail again.

I can't get this past CI as no matter what format I use it will initially be considered invalid.

Expectation

I would like the formatted output to look like this:

import scala.annotation.implicitNotFound

@implicitNotFound(
  """Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin
)
trait Show[T, P, R]

Workaround

import scala.annotation.implicitNotFound

@implicitNotFound("""Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}. 
You may want to define it as an implicit function that is polymorphic function over R.""")
trait Show[T, P, R]

Notes

Possibly related to #192

Repo that reproduces this bug here https://github.com/steinybot/bug-reports/tree/scalafmt/non-idempotent-annotation

@poslegm poslegm added the bug label Jan 20, 2020
@kitbellew
Copy link
Collaborator

@steinybot can you check whether this problem is related to #1506, which was fixed in #1649?

@steinybot
Copy link
Author

@kitbellew looks like it is something else:

~/source/bug-reports scalafmt/non-idempotent-annotation
❯ scalafmt -version
scalafmt 2.3.3-RC2+27-f5eb4b87-SNAPSHOT

~/source/bug-reports scalafmt/non-idempotent-annotation
❯ scalafmt --test
--- /Users/jason/source/bug-reports/src/main/scala/Show.scala
+++ /Users/jason/source/bug-reports/src/main/scala/Show.scala-formatted
@@ -2,4 +2,6 @@

-@implicitNotFound("""Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
-                    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin)
+@implicitNotFound(
+  """Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
+    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin
+)
 trait Show[T, P, R]
error: --test failed

~/source/bug-reports scalafmt/non-idempotent-annotation
❯ scalafmt
Reformatting...
  100.0% [##########] 327 source files formatted

~/source/bug-reports scalafmt/non-idempotent-annotation*
❯ scalafmt --test
--- /Users/jason/source/bug-reports/src/main/scala/Show.scala
+++ /Users/jason/source/bug-reports/src/main/scala/Show.scala-formatted
@@ -2,6 +2,4 @@

-@implicitNotFound(
-  """Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
-    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin
-)
+@implicitNotFound("""Could not find an implicit Show for type ${T}, predicate ${P} and result ${R}.
+                    | You may want to define it as an implicit function that is polymorphic function over R.""".stripMargin)
 trait Show[T, P, R]
error: --test failed

~/source/bug-reports scalafmt/non-idempotent-annotation*
❯ scalafmt
Reformatting...
  100.0% [##########] 327 source files formatted

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

Successfully merging a pull request may close this issue.

3 participants