From da4826886fad1a53b6c09e4de54c58ac6565d32e Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Tue, 1 Aug 2023 13:56:49 +0100 Subject: [PATCH] Update scalafmt config --- .scalafmt.conf | 34 ++++++++- .../com/etsy/sbt/checkstyle/Checkstyle.scala | 69 ++++++++++--------- .../checkstyle/CheckstyleConfigLocation.scala | 11 +-- .../sbt/checkstyle/CheckstyleListener.scala | 6 +- .../sbt/checkstyle/CheckstylePlugin.scala | 30 ++++---- .../checkstyle/CheckstyleSeverityLevel.scala | 11 +-- .../checkstyle/CheckstyleXSLTSettings.scala | 11 +-- 7 files changed, 106 insertions(+), 66 deletions(-) diff --git a/.scalafmt.conf b/.scalafmt.conf index f96d918..4d9a747 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,8 +1,40 @@ -version = 3.5.9 +version = 3.7.11 runner.dialect = scala212source3 maxColumn = 120 +rewrite.rules = [ + Imports + RedundantBraces + RedundantParens + PreferCurlyFors +] + +align.openParenCallSite = false +align.openParenDefnSite = false +danglingParentheses.callSite = false +danglingParentheses.defnSite = false + +# don't align arrows in match statements +align.preset = none + +rewrite { + imports.sort = scalastyle + + redundantBraces { + generalExpressions = false + defnBodies = none + stringInterpolation = true + } +} + +docstrings { + style = Asterisk + blankFirstLine = true + removeEmpty = true + wrap = false +} + fileOverride { # align libraryDependencies in *.sbt "glob:**/*.sbt" { diff --git a/src/main/scala/com/etsy/sbt/checkstyle/Checkstyle.scala b/src/main/scala/com/etsy/sbt/checkstyle/Checkstyle.scala index 11f6178..2fbe3a8 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/Checkstyle.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/Checkstyle.scala @@ -14,34 +14,36 @@ import java.util.Properties import javax.xml.transform.stream.StreamSource import scala.collection.JavaConverters.* -/** A Scala wrapper around the Checkstyle Java API - * - * @author - * Andrew Johnson - * @author - * Joseph Earl - */ +/** + * A Scala wrapper around the Checkstyle Java API + * + * @author + * Andrew Johnson + * @author + * Joseph Earl + */ object Checkstyle { - /** Runs Checkstyle. - * - * Note: any non-Java sources passed to this function will be ignored. - * - * @param sourceFiles - * list of source files to scan. - * @param configLocation - * location of the Checkstyle config to use. - * @param resources - * list of resource files (used if `configLocation` points to the classpath). - * @param outputFile - * file to store the Checkstyle report in. - * @param xsltTransformations - * XML transformations to apply to the Checkstyle report. - * @param severityLevel - * threshold of violations for failing the build if reached. - * @param log - * used to log status of Checkstyle. - */ + /** + * Runs Checkstyle. + * + * Note: any non-Java sources passed to this function will be ignored. + * + * @param sourceFiles + * list of source files to scan. + * @param configLocation + * location of the Checkstyle config to use. + * @param resources + * list of resource files (used if `configLocation` points to the classpath). + * @param outputFile + * file to store the Checkstyle report in. + * @param xsltTransformations + * XML transformations to apply to the Checkstyle report. + * @param severityLevel + * threshold of violations for failing the build if reached. + * @param log + * used to log status of Checkstyle. + */ def checkstyle( sourceFiles: Seq[File], configLocation: CheckstyleConfigLocation, @@ -99,13 +101,14 @@ object Checkstyle { ) } - /** Applies a set of XSLT transformation to the XML file produced by checkstyle - * - * @param input - * The XML file produced by checkstyle - * @param transformations - * The XSLT transformations to be applied - */ + /** + * Applies a set of XSLT transformation to the XML file produced by checkstyle + * + * @param input + * The XML file produced by checkstyle + * @param transformations + * The XSLT transformations to be applied + */ private def applyXSLT( input: File, transformations: Set[CheckstyleXSLTSettings] diff --git a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleConfigLocation.scala b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleConfigLocation.scala index 0170a58..36e9071 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleConfigLocation.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleConfigLocation.scala @@ -5,11 +5,12 @@ import sbt.File import java.io.{FileInputStream, InputStream} import java.net.URLClassLoader -/** Represents a Checkstyle XML configuration located locally, on the class path or remotely at a URL - * - * @author - * Joseph Earl - */ +/** + * Represents a Checkstyle XML configuration located locally, on the class path or remotely at a URL + * + * @author + * Joseph Earl + */ sealed abstract class CheckstyleConfigLocation { def load(resources: Seq[File]): InputStream } diff --git a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleListener.scala b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleListener.scala index 87796e2..04f57c6 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleListener.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleListener.scala @@ -17,10 +17,10 @@ class CheckstyleListener extends AuditListener { override def addError(event: AuditEvent): Unit = { event.getSeverityLevel match { - case SeverityLevel.INFO => infoCount += 1 + case SeverityLevel.INFO => infoCount += 1 case SeverityLevel.WARNING => warningCount += 1 - case SeverityLevel.ERROR => errorCount += 1 - case SeverityLevel.IGNORE => // ignore + case SeverityLevel.ERROR => errorCount += 1 + case SeverityLevel.IGNORE => // ignore } } diff --git a/src/main/scala/com/etsy/sbt/checkstyle/CheckstylePlugin.scala b/src/main/scala/com/etsy/sbt/checkstyle/CheckstylePlugin.scala index 3a0dfb7..8cb3e75 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/CheckstylePlugin.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/CheckstylePlugin.scala @@ -5,15 +5,16 @@ import sbt.* import sbt.Def.Initialize import sbt.Keys.* -/** An SBT plugin to run checkstyle over Java code - * - * @author - * Andrew Johnson - * @author - * Alejandro Rivera - * @author - * Joseph Earl - */ +/** + * An SBT plugin to run checkstyle over Java code + * + * @author + * Andrew Johnson + * @author + * Alejandro Rivera + * @author + * Joseph Earl + */ object CheckstylePlugin extends AutoPlugin { override def trigger: PluginTrigger = allRequirements @@ -39,11 +40,12 @@ object CheckstylePlugin extends AutoPlugin { val CheckstyleXSLTSettings: com.etsy.sbt.checkstyle.CheckstyleXSLTSettings.type = com.etsy.sbt.checkstyle.CheckstyleXSLTSettings - /** Runs checkstyle - * - * @param conf - * The configuration (Compile or Test) in which context to execute the checkstyle command - */ + /** + * Runs checkstyle + * + * @param conf + * The configuration (Compile or Test) in which context to execute the checkstyle command + */ def checkstyleTask(conf: Configuration): Initialize[Task[Unit]] = Def.task { Checkstyle.checkstyle( (conf / sources).value, diff --git a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleSeverityLevel.scala b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleSeverityLevel.scala index 1e07da9..ada9e57 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleSeverityLevel.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleSeverityLevel.scala @@ -1,10 +1,11 @@ package com.etsy.sbt.checkstyle -/** Enumeration of the different Checkstyle severity levels - * - * @author - * Andrew Johnson - */ +/** + * Enumeration of the different Checkstyle severity levels + * + * @author + * Andrew Johnson + */ object CheckstyleSeverityLevel extends Enumeration { type CheckstyleSeverityLevel = Value diff --git a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleXSLTSettings.scala b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleXSLTSettings.scala index 5f36455..c953cab 100644 --- a/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleXSLTSettings.scala +++ b/src/main/scala/com/etsy/sbt/checkstyle/CheckstyleXSLTSettings.scala @@ -2,9 +2,10 @@ package com.etsy.sbt.checkstyle import java.io.File -/** Configuration for a single XSLT transformation of the checkstyle output file - * - * @author - * Andrew Johnson - */ +/** + * Configuration for a single XSLT transformation of the checkstyle output file + * + * @author + * Andrew Johnson + */ final case class CheckstyleXSLTSettings(xslt: File, output: File)