Skip to content

Commit

Permalink
integrate scalafmt code formatting scaffolding (openlawteam#175)
Browse files Browse the repository at this point in the history
* integrate code formatting scaffolding

Since OSS contributors to this repo are more likely to be touching the
JS portion, I left out the "recommend extensions" for Scala for the
default vscode conf, so we dont bug everyone who wants to contribute
to install it.

* apply scalafmt auto fix

* apply lint-style-fix globally

catches a Markdown formatting thing in README via Prettier.
  • Loading branch information
mroth authored Feb 8, 2020
1 parent cbac113 commit 5226ba9
Show file tree
Hide file tree
Showing 9 changed files with 713 additions and 258 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ jobs:
- uses: actions/checkout@v1
- name: Shellcheck Lint
uses: azohra/[email protected]

lint-scala:
name: Run scalafmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: openlawteam/scalafmt-ci@v2
25 changes: 25 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Scalafmt configuration
#
# Reference: https://scalameta.org/scalafmt/docs/configuration.html

# We would like to define an "edition" to freeze the rules without requiring a
# specific version.
#
# In effect, this then enforces a minimum version of scalafmt but allows some
# users to have more recent versions installed on their machine, and lets us
# upgrade the default ruleset all at once for the project if desired.
#
# Unfortunately, IntelliJ parses the conf file on its own prior to passing to
# scalafmt, and it does not yet support the `edition` tag and bombs.
#
# https://intellij-support.jetbrains.com/hc/en-us/requests/2449753

# edition = 2019-12
version = "2.3.2"


project.excludeFilters = ["target/"]

# NOTE: To adhere to OSS community standards, and to have as minimum a gap as
# possible between "default" projects, we do not override any of the style
# defaults.
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": ["esbenp.prettier-vscode"],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
###############################################################################
# Linters (not normally run manually via command line, but here for backup.)
###############################################################################
.PHONY: lint lint-style lint-style-fix lint-code
lint: lint-style lint-code
lint-code: lint-code-js
lint-style: lint-style-js lint-style-scala ## Lint all files for code style
lint-style-fix: lint-style-js-fix lint-style-scala-fix # Automatically fix all files for code style

lint-style-js:
npm run style

lint-style-js-fix:
npm run style:fix

lint-code-js:
npm run lint

lint-code-js-fix:
npm run lint:fix

SCALAFMT_IMAGE = mrothy/scalafmt-native:2.3.2
SCALAFMT_TARGETS = src project build.sbt
SCALAFMT_EXCLUSIONS = target/

lint-style-scala: # Lint scala files for code style
docker run \
-v $$(PWD):/src \
--rm -it \
--workdir /src \
$(SCALAFMT_IMAGE) \
--exclude $(SCALAFMT_EXCLUSIONS) \
--list \
$(SCALAFMT_TARGETS)

lint-style-scala-fix: # Automatically fix scala files for code style
docker run \
-v $$(PWD):/src \
--rm -it \
--workdir /src \
$(SCALAFMT_IMAGE) \
--exclude $(SCALAFMT_EXCLUSIONS) \
$(SCALAFMT_TARGETS)

###############################################################################
# Modified version of self-documenting help script from:
# https://suva.sh/posts/well-documented-makefiles/
#
# This creates a default `help` goal that will document all tasks that are
# annotated with a double comment "#" marker.
###############################################################################
.DEFAULT_GOAL:=help
help: ## Display this help message
@awk 'BEGIN { \
FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n" \
} /^[a-zA-Z0-9_-]+:.*?##/ { \
printf " \033[36m%-12s\033[0m %s\n", $$1, $$2 \
}' $(MAKEFILE_LIST)
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ More detailed documentation about the release process is [here](docs/ReleaseProc

See information about contributing [here](docs/CONTRIBUTING.md).

### Code Formatting

We adhere to standardized code formatting via [Prettier](https://prettier.io)
and [scalafmt](https://scalameta.org/scalafmt/). All PRs will be automatically
checked for adherence. If they do not adhere to standardized formatting, they
should be corrected prior to being merged.

The best way is let your editor handle everything for you everytime you hit
save, see the [Scalafmt Installation
Docs](https://scalameta.org/scalafmt/docs/installation.html) or the OpenLaw
developer setup documentation.

To manually verify, can run `make lint-style` to check and `make lint-style-fix`
to automatically repair all files.

## License

Copyright 2019 Aaron Wright, David Roon, and ConsenSys AG.
Expand Down
40 changes: 25 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ always upgrade in a controlled fashion.
If you wish to update either Scala or SBT, please open an issue and and tag
@openlawteam/infra.
*/
*/
lazy val scalaV = "2.12.10"

lazy val repositories = Seq(
Expand All @@ -23,18 +23,28 @@ lazy val repositories = Seq(
)

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
javacOptions ++= Seq("-Xms512M", "-Xmx1024M", "-Xss1M", "-XX:+CMSClassUnloadingEnabled")
javacOptions ++= Seq(
"-Xms512M",
"-Xmx1024M",
"-Xss1M",
"-XX:+CMSClassUnloadingEnabled"
)

lazy val root = (project in file(".")).settings(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule).withESFeatures(_.withUseECMAScript2015(true))},
resolvers ++= repositories,
organization := "org.openlaw",
name := "openlaw-core-client",
scalaVersion := scalaV,
libraryDependencies ++= Seq(
"org.openlaw" %%% "openlaw-core" % "0.1.57"
),
relativeSourceMaps := true,
artifactPath in (Compile, fullOptJS) := crossTarget.value / "client.js",
artifactPath in (Compile, fastOptJS) := crossTarget.value / "client.js"
).enablePlugins(ScalaJSPlugin)
lazy val root = (project in file("."))
.settings(
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
.withESFeatures(_.withUseECMAScript2015(true))
},
resolvers ++= repositories,
organization := "org.openlaw",
name := "openlaw-core-client",
scalaVersion := scalaV,
libraryDependencies ++= Seq(
"org.openlaw" %%% "openlaw-core" % "0.1.57"
),
relativeSourceMaps := true,
artifactPath in (Compile, fullOptJS) := crossTarget.value / "client.js",
artifactPath in (Compile, fastOptJS) := crossTarget.value / "client.js"
)
.enablePlugins(ScalaJSPlugin)
9 changes: 6 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ logLevel := Level.Warn

resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/"
resolvers += Resolver.url("sbt-plugins", url("https://dl.bintray.com/ssidorenko/sbt-plugins/"))(Resolver.ivyStylePatterns)
resolvers += Resolver.url(
"sbt-plugins",
url("https://dl.bintray.com/ssidorenko/sbt-plugins/")
)(Resolver.ivyStylePatterns)

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31")
addSbtPlugin("org.lyranthe.sbt" % "partial-unification" % "1.1.0")

/* WartRemover currently chokes on ScalaJS and causes lots of false positives.
In the future, we can re-enable here if resikved and then enable it in our build
settings. */
settings. */
// addSbtPlugin("org.wartremover" % "sbt-wartremover" % "2.4.1")

/* Informational tools you may wish to install locally:
"sbt-dependency-graph is an informational tool rather than one that changes
your build, so you will more than likely wish to install it as a global plugin
so that you can use it in any SBT project without the need to explicitly add it
to each one. To do this, add the plugin dependency to
to each one. To do this, add the plugin dependency to
~/.sbt/1.0/plugins/plugins.sbt for sbt 1.0"
Same logic appears to apply to sbt-updates and sbt-dependency check. */
Expand Down
Loading

0 comments on commit 5226ba9

Please sign in to comment.