diff --git a/.scalafix.conf b/.scalafix-scala2.conf similarity index 81% rename from .scalafix.conf rename to .scalafix-scala2.conf index 1a14e24bc..f9ca221c2 100644 --- a/.scalafix.conf +++ b/.scalafix-scala2.conf @@ -9,7 +9,7 @@ ExplicitResultTypes { OrganizeImports { groupedImports = Explode expandRelative = true - removeUnused = true # done already by RemoveUnused rule + removeUnused = true groups = [ "re:javax?\\." "scala." diff --git a/.scalafix-scala3.conf b/.scalafix-scala3.conf new file mode 100644 index 000000000..cfbb6de23 --- /dev/null +++ b/.scalafix-scala3.conf @@ -0,0 +1,15 @@ +rules = [ + OrganizeImports +] + +OrganizeImports { + groupedImports = Explode + expandRelative = true + removeUnused = false + groups = [ + "re:javax?\\." + "scala." + "scala.meta." + "*" + ] +} diff --git a/project/ScalafixBuild.scala b/project/ScalafixBuild.scala index 5a0ca61f6..0d2ff064c 100644 --- a/project/ScalafixBuild.scala +++ b/project/ScalafixBuild.scala @@ -179,6 +179,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { import autoImport._ override def globalSettings: Seq[Def.Setting[_]] = List( + excludeLintKeys += scalafixConfig, // defined on projects where ScalafixPlugin is disabled stableVersion := (ThisBuild / version).value.replaceFirst("\\+.*", ""), resolvers ++= Resolver.sonatypeOssRepos("snapshots") ++ @@ -330,16 +331,23 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { private def configSettings: Seq[Def.Setting[_]] = List( // Workaround for https://github.com/scalacenter/scalafix/issues/1592: - // effectively skip scalafix[All] if the scala binary version of the project - // does not match the scalafix one (which cannot be per-project as it must be - // defined on ThisBuild) + // effectively skip scalafix[All] on 2.x projects not matching scalafixScalaBinaryVersion scalafix / unmanagedSources := { val prev = (scalafix / unmanagedSources).value - if (scalaBinaryVersion.value == scalafixScalaBinaryVersion.value) { + if ( + Seq(scalafixScalaBinaryVersion.value, "3") + .contains(scalaBinaryVersion.value) + ) { prev } else { Seq() } + }, + scalafixConfig := { + if (scalaBinaryVersion.value.startsWith("2")) + Some(file(".scalafix-scala2.conf")) + else + Some(file(".scalafix-scala3.conf")) } ) diff --git a/scalafix-core/src/main/scala-3/scalafix/util/CompatSemanticdbType.scala b/scalafix-core/src/main/scala-3/scalafix/util/CompatSemanticdbType.scala index 261656afa..7068d2676 100644 --- a/scalafix-core/src/main/scala-3/scalafix/util/CompatSemanticdbType.scala +++ b/scalafix-core/src/main/scala-3/scalafix/util/CompatSemanticdbType.scala @@ -1,7 +1,7 @@ package scalafix.util -import scala.meta.internal.semanticdb.XtensionSemanticdbType import scala.meta.internal.semanticdb.XtensionSemanticdbScope +import scala.meta.internal.semanticdb.XtensionSemanticdbType object CompatSemanticdbType { type SemanticdbType = XtensionSemanticdbType diff --git a/scalafix-reflect/src/main/scala-3/scalafix/internal/reflect/RuleCompiler.scala b/scalafix-reflect/src/main/scala-3/scalafix/internal/reflect/RuleCompiler.scala index 944867c2d..09c1cc712 100644 --- a/scalafix-reflect/src/main/scala-3/scalafix/internal/reflect/RuleCompiler.scala +++ b/scalafix-reflect/src/main/scala-3/scalafix/internal/reflect/RuleCompiler.scala @@ -1,24 +1,23 @@ package scalafix.internal.reflect +import java.io.File + import dotty.tools.dotc.Compiler import dotty.tools.dotc.Run import dotty.tools.dotc.core.Contexts.FreshContext -import dotty.tools.dotc.util.SourceFile -import dotty.tools.dotc.reporting.StoreReporter import dotty.tools.dotc.interactive.InteractiveDriver +import dotty.tools.dotc.reporting.StoreReporter +import dotty.tools.dotc.util.SourceFile import dotty.tools.io.AbstractFile import dotty.tools.io.Directory import dotty.tools.io.PlainDirectory -import dotty.tools.io.VirtualFile import dotty.tools.io.VirtualDirectory +import dotty.tools.io.VirtualFile import dotty.tools.repl.AbstractFileClassLoader - +import metaconfig.ConfError import metaconfig.Configured import metaconfig.Input -import metaconfig.ConfError import metaconfig.Position - -import java.io.File class RuleCompiler( classpath: String, targetDirectory: Option[File] = None diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala index 4b2ee9091..ce8023416 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala @@ -33,9 +33,7 @@ import metaconfig.ConfOps import metaconfig.Configured import metaconfig.internal.ConfGet import scalafix.internal.config.ScalaVersion -import scalafix.internal.rule.ImportMatcher.* -import scalafix.internal.rule.ImportMatcher.--- -import scalafix.internal.rule.ImportMatcher.parse +import scalafix.internal.rule.ImportMatcher._ import scalafix.lint.Diagnostic import scalafix.patch.Patch import scalafix.v1.Configuration diff --git a/scalafix-tests/integration/src/test/scala-3/scalafix/tests/util/compat/CompatSemanticdb.scala b/scalafix-tests/integration/src/test/scala-3/scalafix/tests/util/compat/CompatSemanticdb.scala index 3b0897b3b..34abe8495 100644 --- a/scalafix-tests/integration/src/test/scala-3/scalafix/tests/util/compat/CompatSemanticdb.scala +++ b/scalafix-tests/integration/src/test/scala-3/scalafix/tests/util/compat/CompatSemanticdb.scala @@ -1,6 +1,7 @@ package scalafix.tests.util.compat import java.nio.file.Path + import dotty.tools.dotc.Main object CompatSemanticdb {