Skip to content

Commit 7fdde78

Browse files
committed
add scalafmt
1 parent 60bc07a commit 7fdde78

File tree

11 files changed

+150
-108
lines changed

11 files changed

+150
-108
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
shell: bash
3737
run: |
3838
gpg --import test-key.gpg
39-
sbt -v ++2.12.x clean test scripted
39+
sbt -v ++2.12.x clean scalafmtSbtCheck scalafmtCheckAll test scripted
4040
- name: Build and test (sbt 2.x)
4141
if: ${{ matrix.sbt == 2 }}
4242
shell: bash
4343
run: |
4444
gpg --import test-key.gpg
45-
sbt -v ++3.x clean test scripted
45+
sbt -v ++3.x clean scalafmtCheckAll test scripted

.scalafmt.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version = "3.8.3"
2+
maxColumn = 150
3+
align.tokens = []
4+
docstrings.wrap = keep
5+
docstrings.oneline = keep
6+
docstrings.style = keep
7+
docstrings.forceBlankLineBefore = false
8+
runner.dialect = Scala212Source3
9+
rewrite.scala3.convertToNewSyntax = true
10+
rewrite.scala3.newSyntax.control = false

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ libraryDependencies ++= Seq(
2525
(pluginCrossBuild / sbtVersion) := {
2626
scalaBinaryVersion.value match {
2727
case "2.12" => "1.5.8"
28-
case _ => "2.0.0-M2"
28+
case _ => "2.0.0-M2"
2929
}
3030
}
3131

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
22

33
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.7.0")
4+
5+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ object ConsoleGitRunner extends GitRunner {
1515
val isWindows = System.getProperty("os.name", "").toLowerCase.contains("windows")
1616
isWindows && !isCygwin
1717
}
18-
private lazy val cmd = if(isWindowsShell) Seq("cmd", "/c", "git") else Seq("git")
18+
private lazy val cmd = if (isWindowsShell) Seq("cmd", "/c", "git") else Seq("git")
1919

2020
// in order to enable colors we trick git into thinking we're a pager, because it already knows we're not a tty
2121
val colorSupport: Seq[(String, String)] =
22-
Try{
23-
if(Terminal.console.isAnsiSupported)
22+
Try {
23+
if (Terminal.console.isAnsiSupported)
2424
Seq("GIT_PAGER_IN_USE" -> "1")
2525
else
2626
Seq.empty
@@ -31,9 +31,9 @@ object ConsoleGitRunner extends GitRunner {
3131
IO.createDirectory(cwd)
3232
val full = cmd ++ args
3333
log.debug(cwd.toString + "$ " + full.mkString(" "))
34-
val code = Process(full, cwd, colorSupport *) ! gitLogger
34+
val code = Process(full, cwd, colorSupport*) ! gitLogger
3535
val result = gitLogger.flush(code)
36-
if(code != 0)
36+
if (code != 0)
3737
throw new MessageOnlyException("Nonzero exit code (" + code + ") running git.")
3838
else
3939
result
@@ -43,7 +43,7 @@ object ConsoleGitRunner extends GitRunner {
4343
// reduce log level for git process
4444
private class GitLogger(log: Logger) extends ProcessLogger {
4545
import scala.collection.mutable.ListBuffer
46-
import Level.{ Debug, Info, Error, Value as LogLevel }
46+
import Level.{Debug, Info, Error, Value as LogLevel}
4747

4848
private val msgs: ListBuffer[(LogLevel, String)] = new ListBuffer()
4949

src/main/scala/com/github/sbt/git/GitPlugin.scala

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.sbt.git
22

3-
import sbt._
4-
import Keys._
3+
import sbt.*
4+
import Keys.*
55

66
/** This plugin has all the basic 'git' functionality for other plugins. */
77
object SbtGit {
@@ -15,7 +15,8 @@ object SbtGit {
1515
val gitCurrentTags = SettingKey[Seq[String]]("git-current-tags", "The tags associated with this commit.")
1616
val gitHeadCommit = SettingKey[Option[String]]("git-head-commit", "The commit sha for the top commit of this project.")
1717
val gitHeadMessage = SettingKey[Option[String]]("git-head-message", "The message for the top commit of this project.")
18-
val gitHeadCommitDate = SettingKey[Option[String]]("git-head-commit-date", "The commit date for the top commit of this project in ISO-8601 format.")
18+
val gitHeadCommitDate =
19+
SettingKey[Option[String]]("git-head-commit-date", "The commit date for the top commit of this project in ISO-8601 format.")
1920
val gitDescribedVersion = SettingKey[Option[String]]("git-described-version", "Version as returned by `git describe --tags`.")
2021
val gitUncommittedChanges = SettingKey[Boolean]("git-uncommitted-changes", "Whether there are uncommitted changes.")
2122

@@ -28,12 +29,15 @@ object SbtGit {
2829
val gitTagToVersionNumber = SettingKey[String => Option[String]]("git-tag-to-version-number", "Converts a git tag string to a version number.")
2930

3031
// Component version strings. We use these when determining the actual version.
31-
val formattedShaVersion = settingKey[Option[String]]("Completely formatted version string which will use the git SHA. Override this to change how the SHA version is formatted.")
32+
val formattedShaVersion = settingKey[Option[String]](
33+
"Completely formatted version string which will use the git SHA. Override this to change how the SHA version is formatted."
34+
)
3235
val formattedDateVersion = settingKey[String]("Completely formatted version string which does not rely on git. Used as a fallback.")
3336

3437
// Helper suffix/prefix information for generated default version strings.
3538
val baseVersion = SettingKey[String]("base-version", "The base version number which we will append the git version to.")
36-
val versionProperty = SettingKey[String]("version-property", "The system property that can be used to override the version number. Defaults to `project.version`.")
39+
val versionProperty =
40+
SettingKey[String]("version-property", "The system property that can be used to override the version number. Defaults to `project.version`.")
3741
val uncommittedSignifier = SettingKey[Option[String]]("uncommitted-signifier", "Optional additional signifier to signify uncommitted changes")
3842

3943
// The remote repository we're using.
@@ -44,19 +48,19 @@ object SbtGit {
4448
}
4549

4650
object GitCommand {
47-
import complete._
48-
import complete.DefaultParsers._
51+
import complete.*
52+
import complete.DefaultParsers.*
4953

5054
val action: (State, Seq[String]) => State = { (state, args) =>
5155
val extracted = Project.extract(state)
5256
val (state2, runner) = extracted.runTask(GitKeys.gitRunner, state)
5357
val dir = extracted.get(baseDirectory)
54-
runner(args:_*)(dir, state2.log)
58+
runner(args*)(dir, state2.log)
5559
state2
5660
}
5761

5862
// the git command we expose to the user
59-
val command: Command = Command("git")(s => fullCommand(s)){ (state, arg) =>
63+
val command: Command = Command("git")(s => fullCommand(s)) { (state, arg) =>
6064
val (command, args) = arg
6165
action(state, command +: args)
6266
}
@@ -109,17 +113,22 @@ object SbtGit {
109113
}
110114

111115
// Build settings.
112-
import GitKeys._
116+
import GitKeys.*
113117
def buildSettings = Seq(
114118
useConsoleForROGit := false,
115-
gitReader := new DefaultReadableGit(baseDirectory.value, if (useConsoleForROGit.value) Some(new ConsoleGitReadableOnly(ConsoleGitRunner, file("."), sLog.value)) else None),
119+
gitReader := new DefaultReadableGit(
120+
baseDirectory.value,
121+
if (useConsoleForROGit.value) Some(new ConsoleGitReadableOnly(ConsoleGitRunner, file("."), sLog.value)) else None
122+
),
116123
gitRunner := ConsoleGitRunner,
117124
gitHeadCommit := gitReader.value.withGit(_.headCommitSha),
118125
gitHeadMessage := gitReader.value.withGit(_.headCommitMessage),
119126
gitHeadCommitDate := gitReader.value.withGit(_.headCommitDate),
120127
gitTagToVersionNumber := git.defaultTagByVersionStrategy,
121128
gitDescribePatterns := Seq.empty[String],
122-
gitDescribedVersion := gitReader.value.withGit(_.describedVersion(git.gitDescribePatterns.value)).map(v => git.gitTagToVersionNumber.value(v).getOrElse(v)),
129+
gitDescribedVersion := gitReader.value
130+
.withGit(_.describedVersion(git.gitDescribePatterns.value))
131+
.map(v => git.gitTagToVersionNumber.value(v).getOrElse(v)),
123132
gitCurrentTags := gitReader.value.withGit(_.currentTags),
124133
gitCurrentBranch := Option(gitReader.value.withGit(_.branch)).getOrElse(""),
125134
ThisBuild / gitUncommittedChanges := gitReader.value.withGit(_.hasUncommittedChanges),
@@ -142,9 +151,9 @@ object SbtGit {
142151
)
143152

144153
remoteOrigin match {
145-
case unauthenticated(domain, repo) => buildScmInfo(domain,repo)
146-
case ssh(domain, repo) => buildScmInfo(domain,repo)
147-
case headlessSSH(domain, repo) => buildScmInfo(domain,repo)
154+
case unauthenticated(domain, repo) => buildScmInfo(domain, repo)
155+
case ssh(domain, repo) => buildScmInfo(domain, repo)
156+
case headlessSSH(domain, repo) => buildScmInfo(domain, repo)
148157
case _ => None
149158
}
150159
}
@@ -162,20 +171,19 @@ object SbtGit {
162171
if (projectPatterns == buildPatterns && projectTagToVersionNumber == buildTagToVersionNumber)
163172
(ThisBuild / gitDescribedVersion).value
164173
else gitReader.value.withGit(_.describedVersion(projectPatterns)).map(v => projectTagToVersionNumber(v).getOrElse(v))
165-
},
174+
}
166175
)
167176

168177
/** A Predefined setting to use JGit runner for git. */
169-
def useJGit: Setting[_] = ThisBuild / gitRunner := JGitRunner
178+
def useJGit: Setting[?] = ThisBuild / gitRunner := JGitRunner
170179

171180
/** Setting to use console git for readable ops, to allow working with git worktrees */
172-
def useReadableConsoleGit: Setting[_] = ThisBuild / useConsoleForROGit := true
181+
def useReadableConsoleGit: Setting[?] = ThisBuild / useConsoleForROGit := true
173182

174183
/** Adapts the project prompt to show the current project name *and* the current git branch. */
175-
def showCurrentGitBranch: Setting[_] =
184+
def showCurrentGitBranch: Setting[?] =
176185
shellPrompt := GitCommand.prompt
177186

178-
179187
/** Uses git to control versioning.
180188
*
181189
* Versioning runs through the following:
@@ -185,7 +193,7 @@ object SbtGit {
185193
* 3. if we have a head commit, we attach this to the base version setting "<base-version>.<git commit sha>"
186194
* 4. We append the current timestamp to the base version: "<base-version>.<timestamp>"
187195
*/
188-
def versionWithGit: Seq[Setting[_]] =
196+
def versionWithGit: Seq[Setting[?]] =
189197
Seq(
190198
ThisBuild / versionProperty := "project.version",
191199
ThisBuild / uncommittedSignifier := Some("SNAPSHOT"),
@@ -216,17 +224,19 @@ object SbtGit {
216224
git.flaggedOptional(git.useGitDescribe.value, git.describeVersion((ThisBuild / gitDescribedVersion).value, uncommittedSuffix))
217225
val datedVersion = formattedDateVersion.value
218226
val commitVersion = formattedShaVersion.value
219-
//Now we fall through the potential version numbers...
220-
git.makeVersion(Seq(
221-
overrideVersion,
222-
releaseVersion,
223-
describedVersion,
224-
commitVersion
225-
)) getOrElse datedVersion // For when git isn't there at all.
227+
// Now we fall through the potential version numbers...
228+
git.makeVersion(
229+
Seq(
230+
overrideVersion,
231+
releaseVersion,
232+
describedVersion,
233+
commitVersion
234+
)
235+
) getOrElse datedVersion // For when git isn't there at all.
226236
}
227237
)
228238

229-
def versionProjectWithGit: Seq[Setting[_]] =
239+
def versionProjectWithGit: Seq[Setting[?]] =
230240
Seq(
231241
ThisProject / useGitDescribe := false,
232242
ThisProject / version := {
@@ -240,13 +250,15 @@ object SbtGit {
240250
git.flaggedOptional(git.useGitDescribe.value, git.describeVersion((ThisProject / gitDescribedVersion).value, uncommittedSuffix))
241251
val datedVersion = formattedDateVersion.value
242252
val commitVersion = formattedShaVersion.value
243-
//Now we fall through the potential version numbers...
244-
git.makeVersion(Seq(
245-
overrideVersion,
246-
releaseVersion,
247-
describedVersion,
248-
commitVersion
249-
)) getOrElse datedVersion // For when git isn't there at all.
253+
// Now we fall through the potential version numbers...
254+
git.makeVersion(
255+
Seq(
256+
overrideVersion,
257+
releaseVersion,
258+
describedVersion,
259+
commitVersion
260+
)
261+
) getOrElse datedVersion // For when git isn't there at all.
250262
}
251263
)
252264

@@ -271,24 +283,23 @@ object SbtGit {
271283
val formattedShaVersion = ThisBuild / GitKeys.formattedShaVersion
272284
val formattedDateVersion = ThisBuild / GitKeys.formattedDateVersion
273285

274-
275286
val defaultTagByVersionStrategy: String => Option[String] = { tag =>
276-
if(tag matches "v[0-9].*") Some(tag drop 1)
287+
if (tag matches "v[0-9].*") Some(tag drop 1)
277288
else None
278289
}
279290

280-
def defaultFormatShaVersion(baseVersion: Option[String], sha:String, suffix: String):String = {
281-
baseVersion.map(_ +"-").getOrElse("") + sha + suffix
291+
def defaultFormatShaVersion(baseVersion: Option[String], sha: String, suffix: String): String = {
292+
baseVersion.map(_ + "-").getOrElse("") + sha + suffix
282293
}
283294

284-
def defaultFormatDateVersion(baseVersion:Option[String], date:java.util.Date):String = {
295+
def defaultFormatDateVersion(baseVersion: Option[String], date: java.util.Date): String = {
285296
val df = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss")
286297
df setTimeZone java.util.TimeZone.getTimeZone("GMT")
287-
baseVersion.map(_ +"-").getOrElse("") + (df format (new java.util.Date))
298+
baseVersion.map(_ + "-").getOrElse("") + (df format (new java.util.Date))
288299
}
289300

290301
def flaggedOptional(flag: Boolean, value: Option[String]): Option[String] =
291-
if(flag) value
302+
if (flag) value
292303
else None
293304

294305
def makeUncommittedSignifierSuffix(hasUncommittedChanges: Boolean, uncommittedSignifier: Option[String]): String =
@@ -339,8 +350,8 @@ object GitPlugin extends AutoPlugin {
339350
def useReadableConsoleGit = SbtGit.useReadableConsoleGit
340351
def showCurrentGitBranch = SbtGit.showCurrentGitBranch
341352
}
342-
override def buildSettings: Seq[Setting[_]] = SbtGit.buildSettings
343-
override def projectSettings: Seq[Setting[_]] = SbtGit.projectSettings
353+
override def buildSettings: Seq[Setting[?]] = SbtGit.buildSettings
354+
override def projectSettings: Seq[Setting[?]] = SbtGit.projectSettings
344355
}
345356

346357
/** Adapter to auto-enable git versioning. i.e. the sbt 0.13.5+ mechanism of turning it on. */
@@ -352,5 +363,5 @@ object GitVersioning extends AutoPlugin {
352363
/** Adapter to enable the git prompt. i.e. rich prompt based on git info. */
353364
object GitBranchPrompt extends AutoPlugin {
354365
override def requires = GitPlugin
355-
override def projectSettings = SbtGit.showCurrentGitBranch
366+
override def projectSettings = SbtGit.showCurrentGitBranch
356367
}

src/main/scala/com/github/sbt/git/GitRunner.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.sbt.git
22

3-
import sbt._
3+
import sbt.*
44

55
/** An interface to run git commands. */
66
trait GitRunner {
@@ -12,7 +12,7 @@ trait GitRunner {
1212
def commitAndPush(msg: String, tag: Option[String] = None)(repo: File, log: Logger): Unit = {
1313
apply("add", ".")(repo, log)
1414
apply("commit", "-m", msg, "--allow-empty")(repo, log)
15-
for(tagString <- tag) apply("tag", tagString)(repo, log)
15+
for (tagString <- tag) apply("tag", tagString)(repo, log)
1616
push(repo, log)
1717
}
1818
/** Pushes local commits to the remote branch. */
@@ -21,8 +21,9 @@ trait GitRunner {
2121
def pull(cwd: File, log: Logger) = apply("pull")(cwd, log)
2222
/** Updates the cwd from a remote branch. If the local git repo doesn't exist, will clone it into existence. */
2323
def updated(remote: String, branch: Option[String], cwd: File, log: Logger): Unit =
24-
if(cwd.exists) pull(cwd, log)
25-
else branch match {
24+
if (cwd.exists) pull(cwd, log)
25+
else
26+
branch match {
2627
case None => apply("clone", remote, ".")(cwd, log)
2728
case Some(b) => apply("clone", "-b", b, remote, ".")(cwd, log)
2829
}

0 commit comments

Comments
 (0)