Skip to content

Commit

Permalink
OrganizeImports: don't turn non-wildcard * into _
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Jan 30, 2024
1 parent 0b9c628 commit b10a634
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,11 @@ class OrganizeImports(
case i @ Importee.Unimport(_) =>
patchSyntax(i, i.copy().syntax, dialectAlwaysRequiresBraces)
case i @ Importee.Wildcard() =>
patchSyntax(i, i.copy().syntax, false)
// * is a valid type, which is parsed as Importee.Wildcard with
// the Scala 3 dialect. If the target dialect does not support
// star wildcard, it would be incorrectly turned into _.
if (i.pos.text != "*" || targetDialect.allowStarWildcardImport)
patchSyntax(i, i.copy().syntax, false)
case i =>
patchSyntax(i, i.syntax, false)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
rules = [OrganizeImports]
OrganizeImports.removeUnused = false
OrganizeImports.targetDialect = Scala2
*/
package test.organizeImports

import WildcardType.*
import WildcardType.`*`
import WildcardType.Other

object ImportWildcardType
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test.organizeImports

import WildcardType.*
import WildcardType.*
import WildcardType.Other

object ImportWildcardType
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package test.organizeImports

object WildcardType {
object *
object Other
}

0 comments on commit b10a634

Please sign in to comment.