From 2cbc42fd0809b60b1ee2116657d18b3f44f8aef1 Mon Sep 17 00:00:00 2001 From: Nikolay Tatarinov <5min4eq.unity@gmail.com> Date: Fri, 24 Jun 2016 02:48:45 +0300 Subject: Scalafmt plugin implementation (#156) * scalariform: improve logging, declare tasks final * scalafmt plugin implementation * add scalafmt and scalariform plugins and examples to tests * fix logging guarded logging behaviour * add notes about formatting check to README * fix compilation error in examples --- plugins/scalariform/Scalariform.scala | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'plugins/scalariform') diff --git a/plugins/scalariform/Scalariform.scala b/plugins/scalariform/Scalariform.scala index 1f6e51f..0612469 100644 --- a/plugins/scalariform/Scalariform.scala +++ b/plugins/scalariform/Scalariform.scala @@ -4,13 +4,12 @@ import java.io.File import java.nio.file.FileSystems import java.nio.file.Files._ -import scala.util.Try import scalariform.formatter.ScalaFormatter import scalariform.formatter.preferences.FormattingPreferences import scalariform.parser.ScalaParserException trait Scalariform extends BaseBuild { - def scalariformFormat: ExitCode = { + final def scalariformFormat: ExitCode = { Scalariform.format(sourceFiles, scalariformPreferences, scalaVersion) ExitCode.Success } @@ -35,7 +34,7 @@ object Scalariform { private val scalaFileMatcher = FileSystems.getDefault.getPathMatcher("glob:**.scala") - def format(files: Seq[File], preferences: FormattingPreferences, scalaVersion: String) = { + def format(files: Seq[File], preferences: FormattingPreferences, scalaVersion: String): Unit = { var reformattedCount: Int = 0 for (file <- files if file.exists) { val path = file.toPath @@ -52,11 +51,11 @@ object Scalariform { reformattedCount += 1 } } catch { - case e: ScalaParserException => System.err.println(s"Scalariform parser error: ${e.getMessage} when formatting source: $file") + case e: ScalaParserException => System.err.println(s"Scalariform parser error: ${e.getMessage} when formatting: $file") } } } - System.err.println(s"Reformatted $reformattedCount Scala sources") + if (reformattedCount > 0) System.err.println(s"Formatted $reformattedCount Scala sources") } } -- cgit v1.2.3