From 04c32802ede1fbac54ba5d52e76c2a99aabfb61d Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sun, 21 Nov 2021 22:56:08 -0800 Subject: [PATCH] ScalafmtDynamic: inline ignore check --- .../org/scalafmt/dynamic/ScalafmtDynamic.scala | 13 ++++--------- .../scalafmt/dynamic/ScalafmtReflectConfig.scala | 3 +++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtDynamic.scala b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtDynamic.scala index 488c4bc58c..da456111ac 100644 --- a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtDynamic.scala +++ b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtDynamic.scala @@ -190,7 +190,9 @@ final case class ScalafmtDynamic( } else { config } - if (isIgnoredFile(filename, configWithDialect)) { + if ( + respectExcludeFilters && !configWithDialect.isIncludedInProject(file) + ) { reporter.excluded(file) code } else { @@ -202,13 +204,6 @@ final case class ScalafmtDynamic( } } - private def isIgnoredFile( - filename: String, - config: ScalafmtReflectConfig - ): Boolean = { - respectExcludeFilters && !config.isIncludedInProject(filename) - } - private def readVersion(config: Path): FormatEval[ScalafmtVersion] = { Try { ConfigFactory.parseFile(config.toFile).getString("version") @@ -240,7 +235,7 @@ final case class ScalafmtDynamic( formatted => formatted ) override def matchesProjectFilters(file: Path): Boolean = - cfg.isIncludedInProject(file.toString) + cfg.isIncludedInProject(file) } } diff --git a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflectConfig.scala b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflectConfig.scala index 9eba1b4a61..7b02d0966a 100644 --- a/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflectConfig.scala +++ b/scalafmt-dynamic/src/main/scala/org/scalafmt/dynamic/ScalafmtReflectConfig.scala @@ -24,6 +24,9 @@ class ScalafmtReflectConfig private[dynamic] (val fmtReflect: ScalafmtReflect)( @inline def getVersion = fmtReflect.version + @inline def isIncludedInProject(path: Path): Boolean = + isIncludedInProject(path.toString) + def isIncludedInProject(filename: String): Boolean = projectMatcherField.invokeAs[Boolean]("matches", filename.asParam)