Skip to content

Commit

Permalink
ScalafmtDynamic: refactor tryFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 22, 2021
1 parent 4b8afcf commit 347c536
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ final case class ScalafmtDynamic(
file: Path,
code: String,
config: ScalafmtReflectConfig
): FormatResult =
if (respectExcludeFilters && !config.isIncludedInProject(file)) {
reporter.excluded(file)
Right(code)
} else
tryForceFormat(file, code, config)

private def tryForceFormat(
file: Path,
code: String,
config: ScalafmtReflectConfig
): FormatResult = {
Try {
val filename = file.toString
Expand All @@ -190,14 +201,7 @@ final case class ScalafmtDynamic(
} else {
config
}
if (
respectExcludeFilters && !configWithDialect.isIncludedInProject(file)
) {
reporter.excluded(file)
code
} else {
configWithDialect.format(code, Some(file))
}
configWithDialect.format(code, Some(file))
}.toEither.left.map {
case ReflectionException(e) => UnknownError(e)
case e => UnknownError(e)
Expand Down

0 comments on commit 347c536

Please sign in to comment.