From 014a7654db71b151198164da65ef610f539cdac1 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Tue, 23 Jan 2024 08:22:27 +1100 Subject: [PATCH] Add scalafmt --- .github/workflows/format.yml | 23 +++++++++++++++++++++++ .scalafmt.conf | 26 ++++++++++++++++++++++++++ project/plugins.sbt | 1 + 3 files changed, 50 insertions(+) create mode 100644 .github/workflows/format.yml create mode 100644 .scalafmt.conf diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..c7698ac --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,23 @@ +name: Scalafmt + +permissions: {} + +on: + pull_request: + branches: ['**'] + +jobs: + build: + name: Code is formatted + runs-on: ubuntu-latest + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Check project is formatted + uses: jrouly/scalafmt-native-action@v3 + with: + arguments: '--list --mode diff-ref=origin/main' diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..75e1b1f --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,26 @@ +version = 3.7.17 +runner.dialect = scala212 +maxColumn = 120 +project.git = true + +# 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.style = Asterisk + +# This also seems more idiomatic to include whitespace in import x.{ yyy } +spaces.inImportCurlyBraces = true + +align.tokens."+" = [ + { + code = "%" + owners = [ + { regex = "Term.ApplyInfix" } + ] + }, + { + code = "%%" + owners = [ + { regex = "Term.ApplyInfix" } + ] + } +] diff --git a/project/plugins.sbt b/project/plugins.sbt index 7a811dd..23658cb 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,2 +1,3 @@ addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.22.0") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")