Skip to content

Commit

Permalink
Add scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Bogacz committed Oct 6, 2024
1 parent 4c005c4 commit 19f6dec
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ bazel-testlogs
.metals
.vscode
.ijwb
projectview.bazelproject
projectview.bazelproject
.DS_Store
42 changes: 42 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version = "3.6.1"

runner.dialect = "Scala213Source3"

style = defaultWithAlign
maxColumn = 160

continuationIndent.callSite = 2
continuationIndent.defnSite = 2
continuationIndent.extendSite = 2
danglingParentheses.preset = true

newlines {
beforeCurlyLambdaParams = multilineWithCaseOnly
sometimesBeforeColonInMethodReturnType = false
topLevelBodyIfMinStatements = [before]
topLevelBodyMinStatements = 2
}

align {
arrowEnumeratorGenerator = false
ifWhileOpenParen = false
openParenCallSite = false
openParenDefnSite = false
}

align.preset = some

docstrings.style = Asterisk
docstrings.wrap = yes

rewrite {
rules = [RedundantBraces, Imports]
redundantBraces.maxLines = 1
imports.sort = scalastyle
imports.expand = true
}

spaces {
beforeContextBoundColon = Never
inImportCurlyBraces = false
}
File renamed without changes.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Scala project build by Bazel

## Dependencies
After changing dependencies, make sure to run
```bash
bazel run @unpinned_maven//:pin
```

## Docker image

Build image
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", "
scalatest_repositories()

scalatest_toolchain()

load("@io_bazel_rules_scala//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories")

scalafmt_default_config()

scalafmt_repositories()
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

scala_binary(
name = "runner",
srcs = ["Runner.scala"],
format = True,
main_class = "cmd.Runner",
deps = ["//src/main/scala/lib:greeting"],
)
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/cmd/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import lib.Greeting

object Runner {
def main(args: Array[String]): Unit = {
def main(args: Array[String]): Unit =
println(Greeting.createHiMessage("Alex"))
}
}
}
4 changes: 1 addition & 3 deletions src/main/scala/lib/BUILD → src/main/scala/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")

scala_library(
name = "greeting",
srcs = ["Greeting.scala"],
visibility = ["//visibility:public"],
)
)
4 changes: 1 addition & 3 deletions src/test/scala/BUILD → src/test/scala/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_test")

scala_test(
name = "tests",
srcs = glob(["**/*.scala"]),
deps = [
"//src/main/scala/lib:greeting",
"@maven//:org_scala_lang_modules_scala_xml_2_13",
],
)
)
Empty file added tools/BUILD.bazel
Empty file.
Empty file added tools/build_rules/BUILD.bazel
Empty file.
1 change: 1 addition & 0 deletions tools/build_rules/prelude_bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
load("//tools:scala.bzl", "scala_library", "scala_macro_library","scala_binary", "scala_test")
8 changes: 8 additions & 0 deletions tools/scala.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@io_bazel_rules_scala//scala:advanced_usage/scala.bzl", "make_scala_binary", "make_scala_junit_test", "make_scala_library", "make_scala_macro_library", "make_scala_test")
load("@io_bazel_rules_scala//scala/scalafmt:phase_scalafmt_ext.bzl", "ext_scalafmt")

# Scalafmt - https://github.com/bazelbuild/rules_scala/blob/master/docs/phase_scalafmt.md#intellij-plugin-support
scala_binary = make_scala_binary(ext_scalafmt)
scala_library = make_scala_library(ext_scalafmt)
scala_macro_library = make_scala_macro_library(ext_scalafmt)
scala_test = make_scala_test(ext_scalafmt)

0 comments on commit 19f6dec

Please sign in to comment.