aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 17:01:30 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-11 18:30:24 -0500
commit3f68499ec4768e2ae1bfe2e390ba66a90b190fc0 (patch)
treed9c85a9bef52d22d1db697bd9276bedca581c547 /plugins
parent163bbc8f1d78750196b30a46a888e7e65ace5454 (diff)
downloadcbt-3f68499ec4768e2ae1bfe2e390ba66a90b190fc0.tar.gz
cbt-3f68499ec4768e2ae1bfe2e390ba66a90b190fc0.tar.bz2
cbt-3f68499ec4768e2ae1bfe2e390ba66a90b190fc0.zip
Document CBT plugin style guide and adjust Scalafmt plugin accordingly
Diffstat (limited to 'plugins')
-rw-r--r--plugins/scalafmt/Scalafmt.scala21
1 files changed, 8 insertions, 13 deletions
diff --git a/plugins/scalafmt/Scalafmt.scala b/plugins/scalafmt/Scalafmt.scala
index 9d42cbd..5535964 100644
--- a/plugins/scalafmt/Scalafmt.scala
+++ b/plugins/scalafmt/Scalafmt.scala
@@ -12,16 +12,15 @@ import java.nio.file._
trait Scalafmt extends BaseBuild {
/** Reformat scala source code according to `scalafmtConfig` rules */
def scalafmt = {
- val scalafmtLib = new ScalafmtLib(lib)
- scalafmtLib.format( sourceFiles ).config(
- scalafmtLib.loadConfig(
+ Scalafmt.apply( lib, sourceFiles.filter(_.string endsWith ".scala") ).config(
+ Scalafmt.loadConfig(
projectDirectory.toPath
) getOrElse ScalafmtConfig.default
)
}
}
-class ScalafmtLib(lib: Lib){ scalafmtLib =>
+object Scalafmt{
def userHome = Option( System.getProperty("user.home") ).map(Paths.get(_))
/** Tries to load config from .scalafmt.conf in given directory or fallback directory */
@@ -34,22 +33,18 @@ class ScalafmtLib(lib: Lib){ scalafmtLib =>
.flatMap ( file => StyleCache.getStyleForFile(file.toString) )
}
- case class format(files: Seq[File]){
- /**
- * @param whiteSpaceInParenthesis more of a hack to make up for missing support in Scalafmt. Does not respect alignment and maxColumn.
- */
+ case class apply( lib: Lib, files: Seq[File] ){
+ /** @param whiteSpaceInParenthesis more of a hack to make up for missing support in Scalafmt. Does not respect alignment and maxColumn. */
case class config(
- config: ScalafmtConfig,
- whiteSpaceInParenthesis: Boolean = false
+ config: ScalafmtConfig, whiteSpaceInParenthesis: Boolean = false
) extends (() => Seq[File]){
- def lib = scalafmtLib
def apply = {
- val (successes, errors) = scalafmtLib.lib.transformFilesOrError(
+ val (successes, errors) = lib.transformFilesOrError(
files,
org.scalafmt.Scalafmt.format(_, config) match {
case Formatted.Success(formatted) => Right(
if( whiteSpaceInParenthesis ){
- scalafmtLib.whiteSpaceInParenthesis(formatted)
+ Scalafmt.whiteSpaceInParenthesis(formatted)
} else formatted
)
case Formatted.Failure( e ) => Left( e )