Skip to content

Commit

Permalink
Merge pull request #230 from mdedetrich/add-and-apply-scalafmt
Browse files Browse the repository at this point in the history
Add and apply scalafmt
  • Loading branch information
mkurz authored Mar 7, 2024
2 parents 1b6ea64 + 5ebb7d3 commit d3e685c
Show file tree
Hide file tree
Showing 23 changed files with 463 additions and 393 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Scalafmt

permissions: read-all

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'
26 changes: 26 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -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" }
]
}
]
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ developers += Developer(

libraryDependencies ++= Seq(
"org.webjars" % "webjars-locator-core" % "0.56",
"org.specs2" %% "specs2-core" % "4.20.5" % "test",
"junit" % "junit" % "4.13.2" % "test"
"org.specs2" %% "specs2-core" % "4.20.5" % "test",
"junit" % "junit" % "4.13.2" % "test"
)

// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.github.sbt" % "sbt-web-build-base" % "2.0.2")

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
2 changes: 1 addition & 1 deletion sbt-web-tester/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ lazy val root = Project("plugins", file(".")).dependsOn(plugin)
lazy val plugin = RootProject(file("../").getCanonicalFile.toURI)

resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("snapshots")
)
3 changes: 2 additions & 1 deletion src/main/scala-sbt-1.0/com/typesafe/sbt/web/Compat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ object Compat {
// More details:
// [[https://github.com/sbt/sbt-paradox-material-theme/pull/61]]
/**
* @deprecated Use `streams.value.cacheStoreFactory.make("...")` instead
* @deprecated
* Use `streams.value.cacheStoreFactory.make("...")` instead
*/
@deprecated(message = """Use `streams.value.cacheStoreFactory.make("...")` instead""")
def cacheStore(stream: sbt.Keys.TaskStreams, identifier: String): sbt.util.CacheStore =
Expand Down
75 changes: 39 additions & 36 deletions src/main/scala/com/typesafe/sbt/web/CompilationExceptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ object CompileProblems {

/**
* Report compilation problems using the given reporter.
*
* If there are any compilation problems with Error severity, then a
* `CompileProblemsException` is thrown. The exception will contain
* the list of problems.
*
* If there are any compilation problems with Error severity, then a `CompileProblemsException` is thrown. The
* exception will contain the list of problems.
*/
def report[Op,A](reporter: Reporter, problems: Seq[Problem]): Unit = {
def report[Op, A](reporter: Reporter, problems: Seq[Problem]): Unit = {
reporter.reset()
problems.foreach(reporter.log)
reporter.printSummary()
Expand All @@ -25,22 +24,23 @@ object CompileProblems {
}

/**
* Exception thrown by `CompileProblems.report` if there are any problems
* to report. This exception contains the problems so they can be used
* for further processing (e.g. for display by Play).
* Exception thrown by `CompileProblems.report` if there are any problems to report. This exception contains the
* problems so they can be used for further processing (e.g. for display by Play).
*/
class CompileProblemsException(override val problems: Array[Problem])
extends CompileFailed
with FeedbackProvidedException {
extends CompileFailed
with FeedbackProvidedException {

override val arguments: Array[String] = Array.empty
}

/**
* Capture a general problem with the compilation of a source file. General problems
* have no associated line number and are always regarded as errors.
* @param message The message to report.
* @param source The source file containing the general error.
* Capture a general problem with the compilation of a source file. General problems have no associated line number and
* are always regarded as errors.
* @param message
* The message to report.
* @param source
* The source file containing the general error.
*/
class GeneralProblem(val message: String, source: File) extends Problem {
def category(): String = ""
Expand All @@ -66,28 +66,31 @@ class GeneralProblem(val message: String, source: File) extends Problem {

/**
* Capture a line/column position along with the line's content for a given source file.
* @param lineNumber The line number - starts at 1.
* @param lineContent The content of the line itself.
* @param characterOffset The offset character position - starts at 0.
* @param source The associated source file.
* @param lineNumber
* The line number - starts at 1.
* @param lineContent
* The content of the line itself.
* @param characterOffset
* The offset character position - starts at 0.
* @param source
* The associated source file.
*/
class LinePosition(
lineNumber: Int,
override val lineContent: String,
characterOffset: Int,
source: File
) extends Position {
lineNumber: Int,
override val lineContent: String,
characterOffset: Int,
source: File
) extends Position {
def line(): Optional[Integer] = Optional.of(lineNumber)

def offset(): Optional[Integer] = Optional.of(characterOffset)

def pointer(): Optional[Integer] = offset()

def pointerSpace(): Optional[String] = Optional.of(
lineContent.take(pointer().get).map {
case '\t' => '\t'
case x => ' '
})
def pointerSpace(): Optional[String] = Optional.of(lineContent.take(pointer().get).map {
case '\t' => '\t'
case _ => ' '
})

def sourcePath(): Optional[String] = Optional.of(source.getPath)

Expand All @@ -100,15 +103,15 @@ class LinePosition(
* Capture a problem associated with a line number and character offset.
*/
class LineBasedProblem(
override val message: String,
override val severity: Severity,
lineNumber: Int,
characterOffset: Int,
lineContent: String,
source: File
) extends Problem {
override val message: String,
override val severity: Severity,
lineNumber: Int,
characterOffset: Int,
lineContent: String,
source: File
) extends Problem {

def category(): String = ""

override def position: Position = new LinePosition(lineNumber, lineContent, characterOffset, source)
}
}
Loading

0 comments on commit d3e685c

Please sign in to comment.