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 --- examples/scalafmt-example/build/build.scala | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/scalafmt-example/build/build.scala (limited to 'examples/scalafmt-example/build/build.scala') diff --git a/examples/scalafmt-example/build/build.scala b/examples/scalafmt-example/build/build.scala new file mode 100644 index 0000000..6f77108 --- /dev/null +++ b/examples/scalafmt-example/build/build.scala @@ -0,0 +1,29 @@ +import cbt._ +import org.scalafmt.ScalafmtStyle + +class Build(val context: Context) extends BuildBuild with Scalafmt { + override def compile = { + scalafmt + super.compile + } + + override def scalafmtConfig: ScalafmtStyle = ScalafmtStyle.defaultWithAlign + + def breakFormatting = { + import java.nio.file._ + import java.nio.charset.Charset + import scala.collection.JavaConverters._ + val utf8 = Charset.forName("UTF-8") + sourceFiles foreach { file => + try { + val path = file.toPath + val fileLines = Files.readAllLines(path, utf8).asScala + val brokenLines = fileLines map (_.dropWhile(_ ==' ')) + Files.write(path, brokenLines.asJava, utf8) + } catch { + case e: Exception => System.err.print(s"Error happend when breaking formatting: ${e}") + } + } + System.err.println("Done breaking formatting") + } +} -- cgit v1.2.3