8000 Setup for scalafmt by ekrich · Pull Request #4522 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Setup for scalafmt #4522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Setup for scalafmt
  • Loading branch information
ekrich committed Mar 20, 2024
commit 99de4ee5eec87a9c2c09afac46408ed92d30ddb0
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ target/
/linker-interface/**/scalajs-logging-src-jars/
/node_modules/

# scalafmt generated
scripts/.coursier
scripts/.scalafmt*

# IDE specific
.cache
.classpath
Expand Down
52 changes: 52 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -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 = {
"⇒": "=>"
"→": "->"
"←": "<-"
}

20 changes: 20 additions & 0 deletions scripts/scalafmt
Original file line number Diff line number Diff line change
@@ -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 "$@"
0