Skip to content

Commit

Permalink
Merge pull request #1274 from bjaglin/scalafmt
Browse files Browse the repository at this point in the history
scalafmt-core 2.7.5
  • Loading branch information
github-brice-jaglin authored Nov 4, 2020
2 parents b1d8950 + 540e362 commit f6bff33
Show file tree
Hide file tree
Showing 98 changed files with 1,076 additions and 1,006 deletions.
6 changes: 3 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version = 2.3.1
version = 2.7.5
project.git = true
docstrings = Javadoc
docstrings.style = Asterisk
optIn.blankLineBeforeDocstring = true
assumeStandardLibraryStripMargin = true
align = none
align.preset = none
onTestFailure = "To fix this, run `./scalafmt` from the project base directory"
optIn.annotationNewlines = true
project.excludeFilters = [
Expand Down
6 changes: 4 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ lazy val unit = project
libraryDependencies ++= testsDeps,
libraryDependencies ++= List(
jgit,
scalatest.withRevision("3.2.0"), // make sure testkit clients can use recent 3.x versions
scalatest.withRevision(
"3.2.0"
), // make sure testkit clients can use recent 3.x versions
"org.scalameta" %% "testkit" % scalametaV
),
compileInputs.in(Compile, compile) := {
Expand Down Expand Up @@ -257,7 +259,7 @@ lazy val unit = project
semanticdbTargetRoot.in(testsShared, Compile).value,
"sharedSourceroot" ->
baseDirectory.in(ThisBuild).value /
"scalafix-tests" / "shared" / "src" / "main",
"scalafix-tests" / "shared" / "src" / "main",
"sharedClasspath" ->
classDirectory.in(testsShared, Compile).value
),
Expand Down
32 changes: 16 additions & 16 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
// Custom settings to publish scalafix forks to alternative maven repo.
lazy val adhocRepoUri = sys.props("scalafix.repository.uri")
lazy val adhocRepoCredentials = sys.props("scalafix.repository.credentials")
lazy val isCustomRepository = adhocRepoUri != null && adhocRepoCredentials != null
lazy val isCustomRepository =
adhocRepoUri != null && adhocRepoCredentials != null

override def globalSettings: Seq[Def.Setting[_]] = List(
stableVersion := version.in(ThisBuild).value.replaceFirst("\\+.*", ""),
Expand Down Expand Up @@ -308,21 +309,20 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
val currentState = state.value
val ref = thisProjectRef.value
val versions = crossScalaVersions.value
versions.map {
version =>
val withScalaVersion = Project
.extract(currentState)
.appendWithoutSession(
Seq(
scalaVersion.in(ThisBuild) := version,
publishArtifact.in(ThisBuild, packageDoc) := false,
publishArtifact.in(ThisBuild, packageSrc) := false
),
currentState
)
Project
.extract(withScalaVersion)
.runTask(publishLocalTransitive.in(ref), withScalaVersion)
versions.map { version =>
val withScalaVersion = Project
.extract(currentState)
.appendWithoutSession(
Seq(
scalaVersion.in(ThisBuild) := version,
publishArtifact.in(ThisBuild, packageDoc) := false,
publishArtifact.in(ThisBuild, packageSrc) := false
),
currentState
)
Project
.extract(withScalaVersion)
.runTask(publishLocalTransitive.in(ref), withScalaVersion)
}
}
)
Expand Down
4 changes: 3 additions & 1 deletion project/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.23")
unmanagedSources.in(Compile) += baseDirectory.value / ".." / "Dependencies.scala"
unmanagedSources.in(
Compile
) += baseDirectory.value / ".." / "Dependencies.scala"
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ object ScalafixErrorImpl {
val to = ScalafixError.values().toList
assert(from.length == to.length, s"$from != $to")
val map = from.zip(to).toMap
map.foreach {
case (key, value) =>
assert(
key.name.toLowerCase() == value.toString.toLowerCase,
s"$key != $value"
)
map.foreach { case (key, value) =>
assert(
key.name.toLowerCase() == value.toString.toLowerCase,
s"$key != $value"
)
}
map
}
Expand Down
85 changes: 42 additions & 43 deletions scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ case class Args(
@Section("Tab completions")
@Description(
"""|Print out bash tab completions. To install:
|```
|# macOS, requires "brew install bash-completion"
|scalafix --bash > /usr/local/etc/bash_completion.d/scalafix
|# Linux
|scalafix --bash > /etc/bash_completion.d/scalafix
|```
|""".stripMargin
|```
|# macOS, requires "brew install bash-completion"
|scalafix --bash > /usr/local/etc/bash_completion.d/scalafix
|# Linux
|scalafix --bash > /etc/bash_completion.d/scalafix
|```
|""".stripMargin
)
bash: Boolean = false,
@Description(
"""|Print out zsh tab completions. To install:
|```
|scalafix --zsh > /usr/local/share/zsh/site-functions/_scalafix
|unfunction _scalafix
|autoload -U _scalafix
|```
|""".stripMargin
|```
|scalafix --zsh > /usr/local/share/zsh/site-functions/_scalafix
|unfunction _scalafix
|autoload -U _scalafix
|```
|""".stripMargin
)
zsh: Boolean = false,
// TODO: --sbt
Expand Down Expand Up @@ -384,34 +384,33 @@ case class Args(
}

def validate: Configured[ValidatedArgs] = {
baseConfig.andThen {
case (base, scalafixConfig, delegator) =>
(
configuredSourceroot |@|
configuredSymtab |@|
configuredRules(base, scalafixConfig) |@|
resolvedPathReplace |@|
configuredDiffDisable |@|
configuredGlobal
).map {
case (
baseConfig.andThen { case (base, scalafixConfig, delegator) =>
(
configuredSourceroot |@|
configuredSymtab |@|
configuredRules(base, scalafixConfig) |@|
resolvedPathReplace |@|
configuredDiffDisable |@|
configuredGlobal
).map {
case (
((((root, symtab), rulez), pathReplace), diffDisable),
global
) =>
ValidatedArgs(
this,
symtab,
rulez,
scalafixConfig,
classLoader,
root,
pathReplace,
diffDisable,
delegator,
semanticdbFilterMatcher,
global
)
}
) =>
ValidatedArgs(
this,
symtab,
rulez,
scalafixConfig,
classLoader,
root,
pathReplace,
diffDisable,
delegator,
semanticdbFilterMatcher,
global
)
}
}
}
}
Expand Down Expand Up @@ -477,14 +476,14 @@ object Args {
TPrint.make[PathMatcher](_ => "<glob>")
implicit val confPrint: TPrint[Conf] =
TPrint.make[Conf](implicit cfg => TPrint.implicitly[ScalafixConfig].render)
implicit def optionPrint[T](
implicit ev: pprint.TPrint[T]
implicit def optionPrint[T](implicit
ev: pprint.TPrint[T]
): TPrint[Option[T]] =
TPrint.make { implicit cfg =>
ev.render
}
implicit def iterablePrint[C[x] <: Iterable[x], T](
implicit ev: pprint.TPrint[T]
implicit def iterablePrint[C[x] <: Iterable[x], T](implicit
ev: pprint.TPrint[T]
): TPrint[C[T]] =
TPrint.make { implicit cfg =>
s"[${ev.render} ...]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ object CompletionsOps {
s"$assign[$escaped]"
}
names(setting).map { name =>
s""""$repeat${option(Case.camelToKebab(name))}$description$message$action""""
s""""$repeat${option(
Case.camelToKebab(name)
)}$description$message$action""""
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions scalafix-cli/src/main/scala/scalafix/internal/v1/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ object MainOps {
s"Scalafix ${Versions.version}"
def usage: String =
"""|Usage: scalafix [options] [<path> ...]
|""".stripMargin
|""".stripMargin
def description: D =
D.paragraph(
"""|Scalafix is a refactoring and linting tool.
|Scalafix supports both syntactic and semantic linter and rewrite rules.
|Syntactic rules can run on source code without compilation.
|Semantic rules can run on source code that has been compiled with the
|SemanticDB compiler plugin.
|""".stripMargin
|Scalafix supports both syntactic and semantic linter and rewrite rules.
|Syntactic rules can run on source code without compilation.
|Semantic rules can run on source code that has been compiled with the
|SemanticDB compiler plugin.
|""".stripMargin
)

/** Line wrap prose while keeping markdown code fences unchanged. */
Expand Down
25 changes: 12 additions & 13 deletions scalafix-core/src/main/scala/scalafix/config/CustomMessage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ object CustomMessage {
implicit val SymbolDecoder: ConfDecoder[CustomMessage[Symbol.Global]] =
decoder[Symbol.Global](field = "symbol")

implicit def CustomMessageEitherDecoder[A, B](
implicit AB: ConfDecoder[Either[CustomMessage[A], CustomMessage[B]]]
implicit def CustomMessageEitherDecoder[A, B](implicit
AB: ConfDecoder[Either[CustomMessage[A], CustomMessage[B]]]
): ConfDecoder[CustomMessage[Either[A, B]]] =
AB.map {
case Right(msg) =>
Expand All @@ -31,18 +31,17 @@ object CustomMessage {
case obj: Conf.Obj => {
(obj.get[T](field) |@|
obj.getOption[String]("message") |@|
obj.getOption[String]("id")).map {
case ((value, message0), id) =>
val message =
message0.map(msg =>
if (msg.contains("\n")) {
"\n" + msg.stripMargin
} else {
msg
}
)
obj.getOption[String]("id")).map { case ((value, message0), id) =>
val message =
message0.map(msg =>
if (msg.contains("\n")) {
"\n" + msg.stripMargin
} else {
msg
}
)

new CustomMessage(value, message, id)
new CustomMessage(value, message, id)
}
}
case els =>
Expand Down
11 changes: 5 additions & 6 deletions scalafix-core/src/main/scala/scalafix/config/Regex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ class Regex(

object Regex {
implicit val regexDecoder: ConfDecoder[Regex] =
ConfDecoder.instance[Regex] {
case obj: Conf.Obj =>
(obj.get[Pattern]("pattern") |@| obj.getOption[Int]("captureGroup"))
.map {
case (pattern, groupIndex) => new Regex(pattern, groupIndex)
}
ConfDecoder.instance[Regex] { case obj: Conf.Obj =>
(obj.get[Pattern]("pattern") |@| obj.getOption[Int]("captureGroup"))
.map { case (pattern, groupIndex) =>
new Regex(pattern, groupIndex)
}
}

implicit val customMessageRegexDecoder: ConfDecoder[CustomMessage[Regex]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ case class LogContext(
}

object LogContext {
implicit def generate(
implicit line: sourcecode.Line,
implicit def generate(implicit
line: sourcecode.Line,
file: sourcecode.File,
enclosing: sourcecode.Enclosing
): LogContext = LogContext(line, file, enclosing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ object MetaconfigOps {
res.product(configured).map { case (a, b) => b +: a }
}
}
def getKey[T](conf: Conf.Obj, path: String, extraNames: String*)(
implicit ev: ConfDecoder[T]
def getKey[T](conf: Conf.Obj, path: String, extraNames: String*)(implicit
ev: ConfDecoder[T]
): Configured[T] = {
ConfGet.getKey(conf, path +: extraNames) match {
case Some(value) => ev.read(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ object ReaderUtil {
m: Map[String, T],
additionalMessage: PartialFunction[String, String] = PartialFunction.empty
): ConfDecoder[T] =
ConfDecoder.instance[T] {
case Conf.Str(x) =>
m.get(x) match {
case Some(y) =>
Configured.Ok(y)
case None =>
val available = m.keys.mkString(", ")
val extraMsg = additionalMessage.applyOrElse(x, (_: String) => "")
val msg =
s"Unknown input '$x'. Expected one of: $available. $extraMsg"
Configured.NotOk(ConfError.message(msg))
}
ConfDecoder.instance[T] { case Conf.Str(x) =>
m.get(x) match {
case Some(y) =>
Configured.Ok(y)
case None =>
val available = m.keys.mkString(", ")
val extraMsg = additionalMessage.applyOrElse(x, (_: String) => "")
val msg =
s"Unknown input '$x'. Expected one of: $available. $extraMsg"
Configured.NotOk(ConfError.message(msg))
}
}
}
Loading

0 comments on commit f6bff33

Please sign in to comment.