diff --git a/.gitignore b/.gitignore index 5c978cc5cd..b31a61b02a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,10 @@ target/ /linker-interface/**/scalajs-logging-src-jars/ /node_modules/ +# scalafmt generated +scripts/.coursier +scripts/.scalafmt* + # IDE specific .cache .classpath diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000000..638296ff63 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,52 @@ +# Overall we are trying to use default settings to the +# maximum extent possible. Removing non-default +# settings is preferred over adding especially as +# the Scala language evolves and styles change. +# Test upgrades: $ scripts/scalafmt --test 2> diff.txt +version = 3.8.0 +docstrings.style = AsteriskSpace +project.git = true +project.excludePaths = [ + "glob:**/scalalib/**", + "glob:**/project/**", + "glob:**/test-suite/js/src/test/resources/SourceMapTestTemplate.scala" +] + +# Default runner.dialect is deprecated, so set explicitly +runner.dialect = scala213source3 + +# new additions +fileOverride { + "glob:**/scala3/**" { + runner.dialect = scala3 + } +} + +optIn.breakChainOnFirstMethodDot = false + +# Preserve some overflow +newlines.avoidForSimpleOverflow = [tooLong, punct, slc] + +indent.callSite = 4 +indentOperator.exemptScope = aloneArgOrBody +indentOperator.include = ".*" +indentOperator.exclude = "^(?:&&|\\|\\||\\+)$" + +newlines.source = keep + +binPack.preset = true +binPack.parentConstructors = keep +binPack.unsafeCallSite = oneline +binPack.literalsExclude = [] +binPack.literalsIncludeSimpleExpr = true + +# Keep control sites more streamlined +indent.ctrlSite = 4 +danglingParentheses.ctrlSite = false + +rewriteTokens = { + "⇒": "=>" + "→": "->" + "←": "<-" +} + diff --git a/scripts/scalafmt b/scripts/scalafmt new file mode 100755 index 0000000000..fdebe25dab --- /dev/null +++ b/scripts/scalafmt @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -e + +HERE="`dirname $0`" +VERSION=$(sed -nre "s#\s*version[^0-9]+([0-9.]+)#\1#p" $HERE/../.scalafmt.conf) +COURSIER="$HERE/.coursier" +SCALAFMT="$HERE/.scalafmt-$VERSION" + +if [ ! -f $COURSIER ]; then + curl -L -o $COURSIER https://git.io/coursier-cli + chmod +x $COURSIER +fi + +if [ ! -f $SCALAFMT ]; then + $COURSIER bootstrap org.scalameta:scalafmt-cli_2.13:$VERSION -r sonatype:snapshots --main org.scalafmt.cli.Cli -o $SCALAFMT + chmod +x $SCALAFMT +fi + +$SCALAFMT "$@"