-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow printing out only reformatted filenames (#148)
* Modify matchers for written files * Refactor results writers using common base * Add identical copies of tests, to be modified * Allow printing out only reformatted filenames Co-authored-by: Albert Meltzer <[email protected]> Co-authored-by: Ciaran Kearney <[email protected]>
- Loading branch information
1 parent
03e29b2
commit 12812d5
Showing
9 changed files
with
142 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/scala/org/antipathy/mvn_scalafmt/builder/FilesSummaryBuilder.scala
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
src/main/scala/org/antipathy/mvn_scalafmt/io/FormatResultsWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.antipathy.mvn_scalafmt.io | ||
|
||
import org.antipathy.mvn_scalafmt.model.{FileSummary, FormatResult, Summary} | ||
|
||
/** Class for writing formatted source files | ||
*/ | ||
abstract class FormatResultsWriter extends Writer[Seq[FormatResult], Summary] { | ||
|
||
protected val showReformattedOnly: Boolean | ||
protected val formattedDetail: String | ||
protected val unformattedDetail: String | ||
protected def processUnformattedFile(input: FormatResult): Unit | ||
|
||
/** Write the passed in input | ||
* | ||
* @param input The input to write | ||
*/ | ||
final override def write(input: Seq[FormatResult]): Summary = { | ||
val unformattedFiles = input.filter(!_.isFormatted) | ||
unformattedFiles.foreach(processUnformattedFile) | ||
val results = if (showReformattedOnly) unformattedFiles else input | ||
Summary(input.length, unformattedFiles.length, build(results)) | ||
} | ||
|
||
/** Build a summary of the format run from the passed in `FormatResult`s | ||
* @param input The input to build from | ||
* @return The built output | ||
*/ | ||
private def build(formatResults: Seq[FormatResult]): Seq[FileSummary] = | ||
formatResults.map { item => | ||
val isFormatted = item.isFormatted | ||
val details = if (isFormatted) formattedDetail else unformattedDetail | ||
FileSummary(item.sourceFile.getName, details) | ||
} | ||
|
||
} |
23 changes: 6 additions & 17 deletions
23
src/main/scala/org/antipathy/mvn_scalafmt/io/FormattedFilesWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 8 additions & 13 deletions
21
src/main/scala/org/antipathy/mvn_scalafmt/io/TestResultLogWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
package org.antipathy.mvn_scalafmt.io | ||
import org.antipathy.mvn_scalafmt.builder.FilesSummaryBuilder | ||
import org.antipathy.mvn_scalafmt.model.{FileSummaryRequest, FormatResult, Summary} | ||
|
||
import org.antipathy.mvn_scalafmt.model.FormatResult | ||
import org.apache.maven.plugin.logging.Log | ||
|
||
/** Class for writing test results to the log | ||
* | ||
* @param log The maven logger | ||
*/ | ||
class TestResultLogWriter(log: Log) extends Writer[Seq[FormatResult], Summary] with FilesSummaryBuilder { | ||
class TestResultLogWriter(log: Log, val showReformattedOnly: Boolean) extends FormatResultsWriter { | ||
|
||
protected val formattedDetail: String = "Formatted" | ||
protected val unformattedDetail: String = "Requires formatting" | ||
|
||
/** Write the test results to a log | ||
* | ||
* @param input The input to write | ||
*/ | ||
override def write(input: Seq[FormatResult]): Summary = { | ||
input.filter(!_.isFormatted).foreach { item => | ||
log.error(s"unformatted file at: ${item.sourceFile.getCanonicalPath}") | ||
} | ||
Summary( | ||
input.length, | ||
input.count(!_.isFormatted), | ||
build(FileSummaryRequest(input, "Formatted", "Requires formatting")) | ||
) | ||
} | ||
protected def processUnformattedFile(item: FormatResult): Unit = | ||
log.error(s"unformatted file at: ${item.sourceFile.getCanonicalPath}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters