Skip to content

Commit

Permalink
Merge pull request #345 from scala-steward/update/scalafmt-core-3.7.9
Browse files Browse the repository at this point in the history
Update scalafmt-core to 3.7.9
  • Loading branch information
Atry authored Jul 15, 2023
2 parents ad93b69 + 9b2daf9 commit c2860f7
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Scala Steward: Reformat with scalafmt 3.1.2
fb6cfb8aea15a1b339e3ed69e1e96acd7df4cae6

# Scala Steward: Reformat with scalafmt 3.7.9
13ec28ec9e96c5649717916965db38aa925c315f
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
runner.dialect = scala212source3
version = "3.7.5"
version = "3.7.9"
maxColumn = 80
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import sbt._
*/
object ApacheLicense extends AutoPlugin {

private val ApacheLicenseRegex = """^\s*Apache License\s*Version 2\.0, January 2004""".r
private val ApacheLicenseRegex =
"""^\s*Apache License\s*Version 2\.0, January 2004""".r

override def trigger = allRequirements

Expand All @@ -16,7 +17,8 @@ object ApacheLicense extends AutoPlugin {
override def projectSettings = Seq(
licenses ++= {
LicenseFile.licenseFileContent.value match {
case Some(content) if ApacheLicenseRegex.findFirstMatchIn(content).isDefined =>
case Some(content)
if ApacheLicenseRegex.findFirstMatchIn(content).isDefined =>
Seq("Apache" -> url("http://www.apache.org/licenses/"))
case _ =>
Seq.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import sbt._

object LicenseFile extends AutoPlugin {

val licenseFileContent = SettingKey[Option[String]]("license-file-content", "The content of LICENSE file")
val licenseFileContent = SettingKey[Option[String]](
"license-file-content",
"The content of LICENSE file"
)

override def trigger = allRequirements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ object MitLicense extends AutoPlugin {
override def projectSettings = Seq(
licenses ++= {
LicenseFile.licenseFileContent.value match {
case Some(content) if MitLicenseRegex.findFirstMatchIn(content).isDefined =>
case Some(content)
if MitLicenseRegex.findFirstMatchIn(content).isDefined =>
Seq("MIT" -> url("http://opensource.org/licenses/MIT"))
case _ =>
Seq.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ object Git extends AutoPlugin {

override def trigger = allRequirements

val gitDir = SettingKey[Option[File]]("git-dir", ".git directory for current project")
val gitDir =
SettingKey[Option[File]]("git-dir", ".git directory for current project")

val gitWorkTree = SettingKey[Option[File]]("git-work-tree", "Root work tree of current project")
val gitWorkTree = SettingKey[Option[File]](
"git-work-tree",
"Root work tree of current project"
)

val gitRepositoryBuilder = SettingKey[RepositoryBuilder]("git-repository-builder", "")
val gitRepositoryBuilder =
SettingKey[RepositoryBuilder]("git-repository-builder", "")

private def settings = Seq(
gitRepositoryBuilder := {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Keys._
* 杨博 (Yang Bo) <[email protected]>
*/
object GithubActionsDocTitle extends AutoPlugin {
override def requires: Plugins = GithubActionsEnvironmentVariables && JvmPlugin
override def requires: Plugins =
GithubActionsEnvironmentVariables && JvmPlugin

override def trigger: PluginTrigger = allRequirements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ object GithubActionsEnvironmentVariables extends AutoPlugin {
val githubRef = settingKey[String](
"The branch or tag ref that triggered the workflow. For example, refs/heads/feature-branch-1. If neither a branch or tag is available for the event type, the variable will not exist."
)
val githubRepository = settingKey[String]("The owner and repository name. For example, octocat/Hello-World.")
val githubRepository = settingKey[String](
"The owner and repository name. For example, octocat/Hello-World."
)
val githubSha = settingKey[String](
"The commit SHA that triggered the workflow. For example, ffac537e6cbbf934b08745a378932722df287a53."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ object GithubActionsScalaJs extends AutoPlugin {
}
](key: SettingKey[StandardConfig]): Def.Setting[StandardConfig] = {
key := {
key.value.withBatchMode(GithubActionsEnvironmentVariables.githubRepository.?.value.isDefined)
key.value.withBatchMode(
GithubActionsEnvironmentVariables.githubRepository.?.value.isDefined
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ object GithubActionsScalaVersions extends AutoPlugin {
"The Scala versions extracted from the build matrices of Github Actions"
)

private implicit final class YamlPathOps(private val nodes: Seq[Node]) extends AnyVal {
private def keyValue: PartialFunction[NodeTuple, (Node, Node)] = { case tuple =>
(tuple.getKeyNode(), tuple.getValueNode())
private implicit final class YamlPathOps(private val nodes: Seq[Node])
extends AnyVal {
private def keyValue: PartialFunction[NodeTuple, (Node, Node)] = {
case tuple =>
(tuple.getKeyNode(), tuple.getValueNode())
}

def childNodes(key: String): Seq[Node] = {
nodes.flatMap {
case mappingNode: MappingNode =>
mappingNode.getValue().asScala.collect {
case keyValue.extract(keyNode: ScalarNode, value) if keyNode.getValue() == key =>
case keyValue.extract(keyNode: ScalarNode, value)
if keyNode.getValue() == key =>
value
}
case _ =>
Expand All @@ -46,8 +49,9 @@ object GithubActionsScalaVersions extends AutoPlugin {
def childNodes: Seq[Node] = {
nodes.flatMap {
case mappingNode: MappingNode =>
mappingNode.getValue().asScala.collect { case keyValue.extract(_, value) =>
value
mappingNode.getValue().asScala.collect {
case keyValue.extract(_, value) =>
value
}
case sequence: SequenceNode =>
sequence.getValue().asScala
Expand All @@ -58,19 +62,27 @@ object GithubActionsScalaVersions extends AutoPlugin {

}

private implicit def yamlPathOps(node: Node): YamlPathOps = new YamlPathOps(Seq(node))
private implicit def yamlPathOps(node: Node): YamlPathOps = new YamlPathOps(
Seq(node)
)

override def projectSettings = Seq(crossScalaVersions := githubActionsMatrixScalaVersions.value)
override def projectSettings = Seq(
crossScalaVersions := githubActionsMatrixScalaVersions.value
)
override def buildSettings =
Seq(
githubActionsMatrixScalaVersions ++= {
Git.gitWorkTree.value match {
case None =>
Seq.empty
case Some(gitWorkTree) =>
FileTreeView.default.list(gitWorkTree.toGlob / ".github/workflows/*.{yml,yaml}").flatMap {
case (workflowYmlPath, _) =>
val reader = Files.newBufferedReader(workflowYmlPath, scala.io.Codec.UTF8.charSet)
FileTreeView.default
.list(gitWorkTree.toGlob / ".github/workflows/*.{yml,yaml}")
.flatMap { case (workflowYmlPath, _) =>
val reader = Files.newBufferedReader(
workflowYmlPath,
scala.io.Codec.UTF8.charSet
)
try {
val matrix = new Yaml()
.compose(reader)
Expand All @@ -85,18 +97,22 @@ object GithubActionsScalaVersions extends AutoPlugin {
.childNodes("include")
.childNodes
.childNodes("scala")
(scalaNodes ++ includeScalaNodes).collect { case scalarNode: ScalarNode =>
scalarNode.getValue()
(scalaNodes ++ includeScalaNodes).collect {
case scalarNode: ScalarNode =>
scalarNode.getValue()
}.distinct
} finally {
reader.close()
}
}
}
}
},
scalaVersion := githubActionsMatrixScalaVersions.value.headOption.getOrElse(scalaVersion.value),
scalaVersion := githubActionsMatrixScalaVersions.value.headOption
.getOrElse(scalaVersion.value),
crossScalaVersions := githubActionsMatrixScalaVersions.value
)

override def globalSettings = Seq(githubActionsMatrixScalaVersions := Seq.empty)
override def globalSettings = Seq(
githubActionsMatrixScalaVersions := Seq.empty
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Ordering.Implicits._
* 杨博 (Yang Bo) <[email protected]>
*/
object GithubActionsScaladocSourceUrl extends AutoPlugin {
override def requires: Plugins = GithubActionsEnvironmentVariables && GitPlugin
override def requires: Plugins =
GithubActionsEnvironmentVariables && GitPlugin

override def trigger: PluginTrigger = allRequirements

Expand All @@ -22,7 +23,10 @@ object GithubActionsScaladocSourceUrl extends AutoPlugin {
case Some(rootDirectory) =>
originalScalacOptions.indexOf("-sourcepath") match {
case -1 =>
originalScalacOptions ++ Seq("-sourcepath", rootDirectory.toString)
originalScalacOptions ++ Seq(
"-sourcepath",
rootDirectory.toString
)
case i =>
originalScalacOptions.updated(i + 1, rootDirectory.toString)
}
Expand All @@ -35,21 +39,26 @@ object GithubActionsScaladocSourceUrl extends AutoPlugin {
},
scalacOptions in Compile in doc := {
val originalScalacOptions = (scalacOptions in Compile in doc).value
(GitPlugin.gitRepositoryBuilder.?.value, GithubActionsEnvironmentVariables.githubRepository.?.value) match {
(
GitPlugin.gitRepositoryBuilder.?.value,
GithubActionsEnvironmentVariables.githubRepository.?.value
) match {
case (Some(repositoryBuilder), Some(slug)) =>
val repository = repositoryBuilder.build()
try {
val hash = repository.resolve(Constants.HEAD).name
if (VersionNumber(scalaVersion.value).numbers < Seq(3L)) {
val sourceUrl = raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
val sourceUrl =
raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
originalScalacOptions.indexOf("-doc-source-url") match {
case -1 =>
originalScalacOptions ++ Seq("-doc-source-url", sourceUrl)
case i =>
originalScalacOptions.updated(i + 1, sourceUrl)
}
} else {
val pathPrefix = GitPlugin.gitWorkTree.value.fold("")(_.toString())
val pathPrefix =
GitPlugin.gitWorkTree.value.fold("")(_.toString())
originalScalacOptions :+ raw"-source-links:$pathPrefix=github://$slug/$hash"
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ object MimaPreviousVersion extends AutoPlugin {
override def projectSettings: Seq[Def.Setting[_]] =
Seq(
mimaPreviousArtifacts ++= {
val currentModuleID = projectID.value.withExplicitArtifacts(Vector.empty)
previousStableVersion.value.map(currentModuleID.withRevision).toSet: Set[ModuleID]
val currentModuleID =
projectID.value.withExplicitArtifacts(Vector.empty)
previousStableVersion.value
.map(currentModuleID.withRevision)
.toSet: Set[ModuleID]
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ object PackageUnidoc extends AutoPlugin with UnidocKeys {
packageDoc,
Def.taskDyn {
unidocProject.value match {
case None => packageDocMappings
case Some(p) => (unidoc in Compile in p).map(_.flatMap(Path.allSubpaths))
case None => packageDocMappings
case Some(p) =>
(unidoc in Compile in p).map(_.flatMap(Path.allSubpaths))
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ object UnidocProject extends AutoPlugin {
override def requires: Plugins = BaseUnidocPlugin

override def projectSettings = Seq(
PackageUnidoc.autoImport.unidocProject in ThisBuild := Some(thisProjectRef.value)
PackageUnidoc.autoImport.unidocProject in ThisBuild := Some(
thisProjectRef.value
)
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ object ClasspathCache extends AutoPlugin {
val versionNumbers = VersionNumber(scalaVersion.value).numbers
import scala.Ordering.Implicits._
if (versionNumbers >= Seq(2L, 12L, 5L) && versionNumbers < Seq(3L)) {
Seq("-Ycache-plugin-class-loader:last-modified", "-Ycache-macro-class-loader:last-modified")
Seq(
"-Ycache-plugin-class-loader:last-modified",
"-Ycache-macro-class-loader:last-modified"
)
} else {
Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ object Optimization extends AutoPlugin {
override def trigger: PluginTrigger = allRequirements

object autoImport {
val optimization = settingKey[Boolean]("Whether to enable scalac flags for optimization")
val optimization =
settingKey[Boolean]("Whether to enable scalac flags for optimization")
}
import autoImport._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import sbt.{AutoPlugin, Def}

/** Skip duplicate publish.
*
* If cross paths are disabled, then publish will be skipped, unless current scala version is the same as the first
* cross scala version.
* If cross paths are disabled, then publish will be skipped, unless current
* scala version is the same as the first cross scala version.
*
* @author
* 杨博 (Yang Bo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ object DetectScalaVersionsFromTravisYml extends AutoPlugin {
case elementNode: MappingNode =>
val pair = !Each(elementNode.getValue.asScala)
pair.getKeyNode match {
case keyNode: ScalarNode if keyNode.getValue == "scala" =>
case keyNode: ScalarNode
if keyNode.getValue == "scala" =>
pair.getValueNode match {
case valueNode: ScalarNode =>
!Return(valueNode.getValue)
Expand Down Expand Up @@ -95,7 +96,10 @@ object DetectScalaVersionsFromTravisYml extends AutoPlugin {
val travisYmlPath = (gitWorkTree / ".travis.yml").toPath
if (Files.exists(travisYmlPath)) {
val versions = extractScalaVersions {
val reader = Files.newBufferedReader(travisYmlPath, scala.io.Codec.UTF8.charSet)
val reader = Files.newBufferedReader(
travisYmlPath,
scala.io.Codec.UTF8.charSet
)
try {
new Yaml().compose(reader)
} finally {
Expand All @@ -120,7 +124,10 @@ object DetectScalaVersionsFromTravisYml extends AutoPlugin {

if (Files.exists(travisYmlPath)) {
extractScalaVersions {
val reader = Files.newBufferedReader(travisYmlPath, scala.io.Codec.UTF8.charSet)
val reader = Files.newBufferedReader(
travisYmlPath,
scala.io.Codec.UTF8.charSet
)
try {
new Yaml().compose(reader)
} finally {
Expand All @@ -136,5 +143,6 @@ object DetectScalaVersionsFromTravisYml extends AutoPlugin {

override def projectSettings = crossScalaVersionsSetting

override def buildSettings = Seq(crossScalaVersionsSetting, scalaVersionSetting)
override def buildSettings =
Seq(crossScalaVersionsSetting, scalaVersionSetting)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ object ScaladocSourceUrl extends AutoPlugin {
case Some(rootDirectory) =>
originalScalacOptions.indexOf("-sourcepath") match {
case -1 =>
originalScalacOptions ++ Seq("-sourcepath", rootDirectory.toString)
originalScalacOptions ++ Seq(
"-sourcepath",
rootDirectory.toString
)
case i =>
originalScalacOptions.updated(i + 1, rootDirectory.toString)
}
Expand All @@ -30,12 +33,16 @@ object ScaladocSourceUrl extends AutoPlugin {
},
scalacOptions in Compile in doc := {
val originalScalacOptions = (scalacOptions in Compile in doc).value
(GitPlugin.gitRepositoryBuilder.?.value, Travis.travisRepoSlug.?.value) match {
(
GitPlugin.gitRepositoryBuilder.?.value,
Travis.travisRepoSlug.?.value
) match {
case (Some(repositoryBuilder), Some(slug)) =>
val repository = repositoryBuilder.build()
try {
val hash = repository.resolve(Constants.HEAD).name
val sourceUrl = raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
val sourceUrl =
raw"https://github.com/$slug/blob/${hash}€{FILE_PATH}.scala"
originalScalacOptions.indexOf("-doc-source-url") match {
case -1 =>
originalScalacOptions ++ Seq("-doc-source-url", sourceUrl)
Expand Down
Loading

0 comments on commit c2860f7

Please sign in to comment.