Skip to content

Commit

Permalink
update scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jun 25, 2023
1 parent 8d46a02 commit 9a1d836
Show file tree
Hide file tree
Showing 52 changed files with 734 additions and 617 deletions.
9 changes: 6 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
version = 2.0.0
version = 3.7.4
maxColumn = 100
project.git = true
project.excludeFilters = [ /sbt-test/, /input_sources/, /contraband-scala/ ]

# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings = JavaDoc
docstrings.style = Asterisk
docstrings.wrap = no

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
Expand All @@ -16,6 +17,8 @@ align.openParenCallSite = false
align.openParenDefnSite = false

# For better code clarity
danglingParentheses = true
danglingParentheses.preset = true

trailingCommas = preserve

runner.dialect = Scala212Source3
11 changes: 5 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Path._
import com.typesafe.tools.mima.core._, ProblemFilters._

val _ = {
//https://github.com/sbt/contraband/issues/122
// https://github.com/sbt/contraband/issues/122
sys.props += ("line.separator" -> "\n")
}
Global / semanticdbEnabled := !(Global / insideCI).value
Expand Down Expand Up @@ -90,11 +90,10 @@ val mimaSettings = Def settings (
"1.4.0",
"1.5.0",
"1.6.0",
) map (
version =>
organization.value %% moduleName.value % version
cross (if (crossPaths.value) CrossVersion.binary else CrossVersion.disabled)
),
) map (version =>
organization.value %% moduleName.value % version
cross (if (crossPaths.value) CrossVersion.binary else CrossVersion.disabled)
),
)

lazy val lmRoot = (project in file("."))
Expand Down
55 changes: 27 additions & 28 deletions core/src/main/scala/sbt/internal/librarymanagement/JsonUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,33 @@ private[sbt] object JsonUtil {
UpdateReportLite(ur.configurations map { cr =>
ConfigurationReportLite(
cr.configuration.name,
cr.details map {
oar =>
OrganizationArtifactReport(
oar.organization,
oar.name,
oar.modules map { mr =>
ModuleReport(
mr.module,
mr.artifacts,
mr.missingArtifacts,
mr.status,
mr.publicationDate,
mr.resolver,
mr.artifactResolver,
mr.evicted,
mr.evictedData,
mr.evictedReason,
mr.problem,
mr.homepage,
mr.extraAttributes,
mr.isDefault,
mr.branch,
mr.configurations,
mr.licenses,
filterOutArtificialCallers(mr.callers)
)
}
)
cr.details map { oar =>
OrganizationArtifactReport(
oar.organization,
oar.name,
oar.modules map { mr =>
ModuleReport(
mr.module,
mr.artifacts,
mr.missingArtifacts,
mr.status,
mr.publicationDate,
mr.resolver,
mr.artifactResolver,
mr.evicted,
mr.evictedData,
mr.evictedReason,
mr.problem,
mr.homepage,
mr.extraAttributes,
mr.isDefault,
mr.branch,
mr.configurations,
mr.licenses,
filterOutArtificialCallers(mr.callers)
)
}
)
}
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private[librarymanagement] abstract class SemComparatorExtra {

protected def toStringImpl: String = {
val versionStr = Seq(major, minor, patch)
.collect {
case Some(v) => v.toString
.collect { case Some(v) =>
v.toString
}
.mkString(".")
val tagsStr = if (tags.nonEmpty) s"-${tags.mkString("-")}" else ""
Expand Down Expand Up @@ -177,8 +177,8 @@ private[librarymanagement] abstract class SemComparatorFunctions {
}
parse(
numbers
.collect {
case Some(v) => v.toString
.collect { case Some(v) =>
v.toString
}
.mkString(".")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object VersionRange {
case _: NumberFormatException =>
// TODO - if the version doesn't meet our expectations, maybe we just issue a hard
// error instead of softly ignoring the attempt to rewrite.
//sys.error(s"Could not fix version [$revision] into maven style version")
// sys.error(s"Could not fix version [$revision] into maven style version")
revision
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private[sbt] object VersionSchemes {
case x => sys.error(s"unknown version scheme: $x")
}

/** info.versionScheme property will be included into POM after sbt 1.4.0.
/**
* info.versionScheme property will be included into POM after sbt 1.4.0.
*/
def extractFromId(mid: ModuleID): Option[String] = extractFromExtraAttributes(mid.extraAttributes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ object CrossVersionUtil {
private[sbt] val BinCompatV = raw"""$basicVersion(-$tagPattern)?-bin(-.*)?""".r
private val CandidateV = raw"""$basicVersion(-RC\d+)""".r
private val MilestonV = raw"""$basicVersion(-M$tagPattern)""".r
private val NonReleaseV_n = raw"""$basicVersion((?:-$tagPattern)*)""".r // 0-n word suffixes, with leading dashes
private val NonReleaseV_n =
raw"""$basicVersion((?:-$tagPattern)*)""".r // 0-n word suffixes, with leading dashes
private val NonReleaseV_1 = raw"""$basicVersion(-$tagPattern)""".r // 1 word suffix, after a dash
private[sbt] val PartialVersion = raw"""($longPattern)\.($longPattern)(?:\..+)?""".r

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/sbt/librarymanagement/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ final class Configuration private[sbt] (
override def equals(o: Any): Boolean = o match {
case x: Configuration =>
(this.id == x.id) &&
(this.name == x.name) &&
(this.description == x.description) &&
(this.isPublic == x.isPublic) &&
(this.extendsConfigs == x.extendsConfigs) &&
(this.transitive == x.transitive)
(this.name == x.name) &&
(this.description == x.description) &&
(this.isPublic == x.isPublic) &&
(this.extendsConfigs == x.extendsConfigs) &&
(this.transitive == x.transitive)
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ private[librarymanagement] abstract class CrossVersionFunctions {
*/
def fullWith(prefix: String, suffix: String): CrossVersion = Full(prefix, suffix)

/** Cross-versions a module with the binary version (typically the binary Scala version). */
/** Cross-versions a module with the binary version (typically the binary Scala version). */
def binary: CrossVersion = Binary()

/** Disables cross versioning for a module. */
def disabled: CrossVersion = sbt.librarymanagement.Disabled

/** Cross-versions a module with a constant string (typically the binary Scala version). */
/** Cross-versions a module with a constant string (typically the binary Scala version). */
def constant(value: String): CrossVersion = Constant(value)

/**
Expand Down Expand Up @@ -218,7 +218,7 @@ private[librarymanagement] abstract class CrossVersionFunctions {
*/
def scalaApiVersion(v: String): Option[(Long, Long)] = CrossVersionUtil.scalaApiVersion(v)

/** Regular expression that extracts the major and minor components of a version into matched groups 1 and 2.*/
/** Regular expression that extracts the major and minor components of a version into matched groups 1 and 2. */
val PartialVersion = CrossVersionUtil.PartialVersion

/** Extracts the major and minor components of a version string `s` or returns `None` if the version is improperly formatted. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ trait DependencyFilterExtra {
): ArtifactFilter =
new ArtifactFilter {
def apply(a: Artifact): Boolean =
name.accept(a.name) && `type`.accept(a.`type`) && extension.accept(a.extension) && classifier
name.accept(a.name) && `type`.accept(a.`type`) && extension.accept(
a.extension
) && classifier
.accept(a.classifier getOrElse "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,19 @@ class DependencyResolution private[sbt] (lmEngine: DependencyResolutionInterface
((sourceArtifactTypes.toIterable map (_ -> Artifact.SourceClassifier))
:: (docArtifactTypes.toIterable map (_ -> Artifact.DocClassifier)) :: Nil).flatten.toMap
Right(r.substitute { (conf, mid, artFileSeq) =>
artFileSeq map {
case (art, f) =>
// Deduce the classifier from the type if no classifier is present already
art.withClassifier(art.classifier orElse typeClassifierMap.get(art.`type`)) -> f
artFileSeq map { case (art, f) =>
// Deduce the classifier from the type if no classifier is present already
art.withClassifier(art.classifier orElse typeClassifierMap.get(art.`type`)) -> f
}
})
case Left(w) => Left(w)
}
}

protected def directDependenciesNames(module: ModuleDescriptor): String =
(module.directDependencies map {
case mID: ModuleID =>
import mID._
s"$organization % $name % $revision"
(module.directDependencies map { case mID: ModuleID =>
import mID._
s"$organization % $name % $revision"
}).mkString(", ")
}

Expand Down
43 changes: 21 additions & 22 deletions core/src/main/scala/sbt/librarymanagement/EvictionError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,29 @@ final class EvictionError private[sbt] (
val out: mutable.ListBuffer[String] = mutable.ListBuffer()
out += "found version conflict(s) in library dependencies; some are suspected to be binary incompatible:"
out += ""
evictions.foreach({
case (a, scheme) =>
val revs = a.evicteds map { _.module.revision }
val revsStr =
if (revs.size <= 1) revs.mkString else "{" + revs.distinct.mkString(", ") + "}"
val seen: mutable.Set[ModuleID] = mutable.Set()
val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r =>
val rev = r.module.revision
r.callers.toList flatMap { caller =>
if (seen(caller.caller)) Nil
else {
seen += caller.caller
List(f"\t +- ${caller}%-50s (depends on $rev)")
}
evictions.foreach({ case (a, scheme) =>
val revs = a.evicteds map { _.module.revision }
val revsStr =
if (revs.size <= 1) revs.mkString else "{" + revs.distinct.mkString(", ") + "}"
val seen: mutable.Set[ModuleID] = mutable.Set()
val callers: List[String] = (a.evicteds.toList ::: a.winner.toList) flatMap { r =>
val rev = r.module.revision
r.callers.toList flatMap { caller =>
if (seen(caller.caller)) Nil
else {
seen += caller.caller
List(f"\t +- ${caller}%-50s (depends on $rev)")
}
}
val que = if (assumed) "?" else ""
val winnerRev = a.winner match {
case Some(r) => s":${r.module.revision} ($scheme$que) is selected over ${revsStr}"
case _ => " is evicted for all versions"
}
val title = s"\t* ${a.organization}:${a.name}$winnerRev"
val lines = title :: (if (a.showCallers) callers.reverse else Nil) ::: List("")
out ++= lines
}
val que = if (assumed) "?" else ""
val winnerRev = a.winner match {
case Some(r) => s":${r.module.revision} ($scheme$que) is selected over ${revsStr}"
case _ => " is evicted for all versions"
}
val title = s"\t* ${a.organization}:${a.name}$winnerRev"
val lines = title :: (if (a.showCallers) callers.reverse else Nil) ::: List("")
out ++= lines
})
out.toList
}
Expand Down
14 changes: 8 additions & 6 deletions core/src/main/scala/sbt/librarymanagement/EvictionWarning.scala
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ final class EvictionPair private[sbt] (
override def equals(o: Any): Boolean = o match {
case o: EvictionPair =>
(this.organization == o.organization) &&
(this.name == o.name)
(this.name == o.name)
case _ => false
}
override def hashCode: Int = {
Expand Down Expand Up @@ -279,10 +279,12 @@ object EvictionWarning {
}
confs flatMap { confReport =>
confReport.details map { detail =>
if ((detail.modules exists { _.evicted }) &&
!(buffer exists { x =>
(x.organization == detail.organization) && (x.name == detail.name)
})) {
if (
(detail.modules exists { _.evicted }) &&
!(buffer exists { x =>
(x.organization == detail.organization) && (x.name == detail.name)
})
) {
buffer += detail
}
}
Expand All @@ -298,7 +300,7 @@ object EvictionWarning {
module.scalaModuleInfo match {
case Some(s) =>
organization == s.scalaOrganization &&
(name == LibraryID) || (name == CompilerID)
(name == LibraryID) || (name == CompilerID)
case _ => false
}

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/sbt/librarymanagement/ModuleIDExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ private[librarymanagement] abstract class ModuleIDExtra {
protected def toStringImpl: String =
s"""$organization:$name:$revision""" +
(configurations match { case Some(s) => ":" + s; case None => "" }) + {
val attr = attributeString
if (attr == "") ""
else " " + attr
} +
val attr = attributeString
if (attr == "") ""
else " " + attr
} +
(if (extraAttributes.isEmpty) "" else " " + extraString)

protected def attributeString: String = {
Expand Down Expand Up @@ -95,10 +95,10 @@ private[librarymanagement] abstract class ModuleIDExtra {
})

// () required for chaining
/** Do not follow dependencies of this module. Synonym for `intransitive`.*/
/** Do not follow dependencies of this module. Synonym for `intransitive`. */
def notTransitive(): ModuleID = intransitive()

/** Do not follow dependencies of this module. Synonym for `notTransitive`.*/
/** Do not follow dependencies of this module. Synonym for `notTransitive`. */
def intransitive(): ModuleID = withIsTransitive(false)

/**
Expand Down
Loading

0 comments on commit 9a1d836

Please sign in to comment.