Skip to content

Commit

Permalink
Merge pull request #188 from alejandrohdezma/update/scalafmt
Browse files Browse the repository at this point in the history
Update scalafmt to 3.3.3
  • Loading branch information
alejandrohdezma authored Jan 24, 2022
2 parents 97cd583 + c09266f commit c8e0520
Show file tree
Hide file tree
Showing 30 changed files with 148 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Don't edit this file!
# It is automatically updated after every release of https://github.com/alejandrohdezma/sbt-ci
# If you want to suggest a change, please open a PR or issue in that repository
ko_fi: alejandrohdezma
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ jobs:
token: ${{ secrets.GH_APP_TOKEN }}

- name: Checkout project
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # v2.3.5
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
token: ${{ steps.github_app.outputs.token }}
ref: ${{ github.event.pull_request.head.ref }}

- name: Enable auto-merge for this PR
run: gh pr merge --auto --merge ${{github.event.pull_request.number}}
Expand All @@ -73,7 +74,7 @@ jobs:
- name: Commit changes by `sbt generateCiFiles`
uses: alejandrohdezma/actions/commit-and-push@v1
with:
message: Run `sbt generateCiFiles`
message: Run `sbt generateCiFiles` [skip ci]

- name: Run `sbt fix`
uses: alejandrohdezma/actions/scala@v1
Expand All @@ -84,7 +85,7 @@ jobs:
- name: Commit changes by `sbt fix`
uses: alejandrohdezma/actions/commit-and-push@v1
with:
message: Run `sbt fix`
message: Run `sbt fix` [skip ci]

test:
needs: [labeler, ci-steward]
Expand All @@ -103,7 +104,7 @@ jobs:
- openjdk:1.17
steps:
- name: Checkout project
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # v2.3.5
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
ref: ${{ github.head_ref }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # v2.3.5
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
fetch-depth: 0

Expand All @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 # v2.3.5
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
fetch-depth: 0
ref: main
Expand Down
7 changes: 6 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
# To edit the original configurations go to
# https://github.com/alejandrohdezma/sbt-scalafmt-defaults/edit/master/.scalafmt.conf

version = 3.0.6
version = 3.3.3

# This value is automatically set based on your current `ThisBuild / scalaVersion` setting.
# `scala212source3`/`scala213source3` will be set if `scalaVersion` is set to any of those versions
# and `-Xsource:3` option is present under `ThisBuild / scalacOptions`.
runner.dialect = scala212

# Number of maximum characters in a column
maxColumn = 120
Expand Down
15 changes: 6 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# @DESCRIPTION@

[![][github-action-badge]][github-action] [![][maven-badge]][maven] [![][steward-badge]][steward]

## Installation

Add the following line to your `plugins.sbt` file:
Expand All @@ -22,13 +20,12 @@ The included plugin is automatically activated. It will enable `scalafmtOnCompil

> You can add the `.scalafmt.conf` file to the repository's `.gitignore`, since it's going to be automatically re-created on every build.
## Runner-dialect

Since v3.1.0, [the Scalafmt `runner.dialect` option is mandatory](https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects). This plugin automatically sets this option based on your current `ThisBuild / scalaVersion` setting. The `scala212source3`/`scala213source3` will be set if `scalaVersion` is set to those and `-Xsource:3` option is present under `ThisBuild / scalacOptions`.

If for any reason you want to alter the generated dialect or specify the `runner.dialect` for a subset of files using `fileOverride` you can use the [`.scalafmt-extra.conf` file](#extra-configurations).

### Extra configurations

Extra configurations can be added to a file named `.scalafmt-extra.conf` at the root of your repository. The content of this file will be automatically appended to the auto-generated `.scalafmt.conf`.

[github-action]: https://github.com/alejandrohdezma/sbt-scalafmt-defaults/actions
[github-action-badge]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Falejandrohdezma%2Fsbt-scalafmt-defaults%2Fbadge%3Fref%3Dmaster&style=flat
[maven]: https://search.maven.org/search?q=g:%20com.alejandrohdezma%20AND%20a:sbt-scalafmt-defaults
[maven-badge]: https://maven-badges.herokuapp.com/maven-central/com.alejandrohdezma/sbt-scalafmt-defaults/badge.svg?kill_cache=1
[steward]: https://scala-steward.org
[steward-badge]: https://img.shields.io/badge/Scala_Steward-helping-brightgreen.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,42 @@ object SbtScalafmtDefaults extends AutoPlugin {

override def trigger = allRequirements

@SuppressWarnings(Array("scalafix:Disable.blocking.io"))
override def globalSettings: Seq[Def.Setting[_]] =
Seq(
scalafmtOnCompile := !sys.env.contains("CI"),
onLoad := onLoad.value.andThen { state =>
val defaults = Source.fromResource(".scalafmt.conf", getClass.getClassLoader).mkString
IO.write(file(".scalafmt.conf"), defaults)
Seq(scalafmtOnCompile := !sys.env.contains("CI"))

val extra = file(".scalafmt-extra.conf")
@SuppressWarnings(Array("scalafix:Disable.blocking.io", "scalafix:DisableSyntax.=="))
override def buildSettings: Seq[Setting[_]] = Seq(
scalafmtConfig := {
val xSource3 = scalacOptions.value.seq.exists(_ == "-Xsource:3")

if (extra.exists())
IO.append(file(".scalafmt.conf"), "\n" + IO.read(extra))

state
val dialect = scalaVersion.value match {
case v if v.startsWith("2.11") => "scala211"
case v if v.startsWith("2.12") && xSource3 => "scala212source3"
case v if v.startsWith("2.12") => "scala212"
case v if v.startsWith("2.13") && xSource3 => "scala213source3"
case v if v.startsWith("2.13") => "scala213"
case v if v.startsWith("3") => "scala3"
}
)

val defaults = Source
.fromResource(".scalafmt.conf", getClass.getClassLoader)
.getLines()
.toList
.map {
case line if line.contains("runner.dialect") => s"runner.dialect = $dialect"
case line => line
}
.mkString("\n")

IO.write(file(".scalafmt.conf"), defaults)

val extra = file(".scalafmt-extra.conf")

if (extra.exists())
IO.append(file(".scalafmt.conf"), "\n" + IO.read(extra))

file(".scalafmt.conf")
}
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := "2.11.12"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala211")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := "2.12.15"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala212")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ThisBuild / scalaVersion := "2.12.15"
ThisBuild / scalacOptions += "-Xsource:3"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala212source3")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := "2.13.8"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala213")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ThisBuild / scalaVersion := "2.13.8"
ThisBuild / scalacOptions += "-Xsource:3"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala213source3")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ThisBuild / scalaVersion := "3.1.0"

TaskKey[Unit]("checkScalafmtConfFile") := {
val expected = sys
.props("scalafmt.conf.content")
.replace("runner.dialect = scala212", "runner.dialect = scala3")

assert(IO.read(file(".scalafmt.conf")) == expected)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.6.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
addSbtPlugin("com.alejandrohdezma" % "sbt-scalafmt-defaults" % sys.props("plugin.version"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this test ensures the .scalafmt.conf is generated with the correct dialect
> scalafmt
> checkScalafmtConfFile

0 comments on commit c8e0520

Please sign in to comment.