diff options
author | Nikolay Tatarinov <5min4eq.unity@gmail.com> | 2016-06-24 02:48:45 +0300 |
---|---|---|
committer | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-06-23 19:48:45 -0400 |
commit | 2cbc42fd0809b60b1ee2116657d18b3f44f8aef1 (patch) | |
tree | e894a040137e591c4a7664b7353d709298a44f65 /examples/scalafmt-example/build/build.scala | |
parent | 75c32537cd8f29f9d12db37bf06ad942806f0239 (diff) | |
download | cbt-2cbc42fd0809b60b1ee2116657d18b3f44f8aef1.tar.gz cbt-2cbc42fd0809b60b1ee2116657d18b3f44f8aef1.tar.bz2 cbt-2cbc42fd0809b60b1ee2116657d18b3f44f8aef1.zip |
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
Diffstat (limited to 'examples/scalafmt-example/build/build.scala')
-rw-r--r-- | examples/scalafmt-example/build/build.scala | 29 |
1 files changed, 29 insertions, 0 deletions
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") + } +} |