Skip to content

Commit

Permalink
do not fetch nor load OrganizeImports JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Jun 3, 2023
1 parent b10f4f2 commit 2693281
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,29 @@ final case class ScalafixArgumentsImpl(args: Args = Args.default)
customDependenciesCoordinates: util.List[String],
repositories: util.List[Repository]
): ScalafixArguments = {

val OrganizeImportsCoordinates =
"""com\.github\.liancheng.*:organize-imports:.*""".r

val keptDependencies: Seq[String] =
customDependenciesCoordinates.asScala
.collect {
case dep @ OrganizeImportsCoordinates() =>
args.out.println(
s"""Ignoring requested classpath dependency `$dep`,
|as OrganizeImports is a built-in rule since Scalafix 0.11.0.
|You can safely remove that dependency to suppress this warning.
""".stripMargin
)
None
case dep => Some(dep)
}
.toSeq
.flatten

val customDependenciesJARs = ScalafixCoursier.toolClasspath(
repositories,
customDependenciesCoordinates,
keptDependencies.asJava,
Versions.scalaVersion
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,23 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
)
}

test("com.github.liancheng::organize-imports is ignored") {
val rules = api
.withToolClasspath(
Nil.asJava,
Seq("com.github.liancheng::organize-imports:0.6.0").asJava
)
.availableRules()
.asScala
.filter(_.name() == "OrganizeImports")

// only one should be loaded
assert(rules.length == 1)

// ensure it's the built-in one (the external one was marked as experimental)
assert(!rules.head.isExperimental)
}

def removeUnsuedRule(): SemanticRule = {
val config = RemoveUnusedConfig.default
new RemoveUnused(config)
Expand Down

0 comments on commit 2693281

Please sign in to comment.