diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 00000000..bc4b624a --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,8 @@ +style = IntelliJ +maxColumn = 100 + +project.excludeFilters = [ + ".*com/google/.*" + ".*tech/sourced/featurext/generated/.*" + ".*gopkg/in/.*" +] diff --git a/.travis.yml b/.travis.yml index b11e3ac0..11de4b89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -69,7 +69,7 @@ matrix: - scala: 2.11.2 env: STYLE_CHECK=true - script: ./sbt scalastyle + script: make lint-scala - scala: 2.11.2 env: FE_PYTHON_TEST=true diff --git a/Makefile b/Makefile index 3b7b74bb..17b3f213 100644 --- a/Makefile +++ b/Makefile @@ -27,3 +27,13 @@ format-python: lint-python: $(YAPF_CMD) --diff + +format-scala: + $(SBT) scalafmt + $(SBT) test:scalafmt + $(SBT) sbt:scalafmt + +lint-scala: + $(SBT) scalafmt::test + $(SBT) test:scalafmt::test + $(SBT) sbt:scalafmt::test diff --git a/README.md b/README.md index 87685e31..fa18b155 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,18 @@ To generate protobuf messages fixtures you may use [bblfsh-sdk-tools](https://gi bblfsh-sdk-tools fixtures -p .proto -l ``` +This project uses [scalafmt](http://scalameta.org/scalafmt) formatting. You can configure IntelliJ IDEA to use the same formatting configuration. To do so, follow the [scalafmt instructions](http://scalameta.org/scalafmt/#IntelliJ). + +To check if the code follows the project style, use the linters +``` +make lint-scala +``` + +To fix formatting issues, use the formatters +``` +make format-scala +``` + ## License Copyright (C) 2017 source{d}. diff --git a/build.sbt b/build.sbt index 8ee0c075..8dc6ccbf 100644 --- a/build.sbt +++ b/build.sbt @@ -102,15 +102,3 @@ publishTo := { Some("releases" at nexus + "service/local/staging/deploy/maven2") } } - -scalastyleSources in Compile := { - // all .scala files in "src/main/scala" - val scalaSourceFiles = ((scalaSource in Compile).value ** "*.scala").get - val fSep = java.io.File.separator - val dirsNameToExclude = List( - "com" + fSep + "google", - "tech" + fSep + "sourced" + fSep + "featurext" + fSep + "generated", - "gopkg" + fSep + "in" - ) - scalaSourceFiles.filterNot(f => dirsNameToExclude.exists(dir => f.getAbsolutePath.contains(dir))) -} diff --git a/project/plugins.sbt b/project/plugins.sbt index 98efea74..b02b3573 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5") addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") -addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.2") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") +addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") diff --git a/scalastyle-config.xml b/scalastyle-config.xml deleted file mode 100644 index 15c6ce16..00000000 --- a/scalastyle-config.xml +++ /dev/null @@ -1,98 +0,0 @@ - - Scalastyle standard configuration - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -