Skip to content

Commit

Permalink
Merge pull request #123 from xuwei-k/transversers
Browse files Browse the repository at this point in the history
add some implicit imports for Scala 2.13.13. sort imports
  • Loading branch information
xuwei-k authored Mar 18, 2024
2 parents 27038c5 + add4e60 commit c9ca076
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
12 changes: 8 additions & 4 deletions core/src/main/scala/scalameta_ast/ScalametaAST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,15 @@ class ScalametaAST {
): String = {
val p = patchCode(patch)
val imports = List[List[String]](
List("scalafix.Patch"),
p.imports,
List(
"scala.meta.transversers._",
"scalafix.Patch",
"scalafix.v1.SyntacticDocument",
"scalafix.v1.SyntacticRule",
"scalafix.v1.XtensionSeqPatch",
)
).flatten.map("import " + _)
).flatten.map("import " + _).sorted
s"""${header(x = x, packageName = packageName, wildcardImport = wildcardImport, parsed = parsed)}
|${imports.mkString("\n")}
|
Expand All @@ -571,13 +573,15 @@ class ScalametaAST {
): String = {
val p = patchCode(patch)
val imports = List[List[String]](
List("scalafix.Patch"),
p.imports,
List(
"scala.meta.transversers._",
"scalafix.Patch",
"scalafix.v1.SemanticDocument",
"scalafix.v1.SemanticRule",
"scalafix.v1.XtensionSeqPatch",
)
).flatten.map("import " + _)
).flatten.map("import " + _).sorted
s"""${header(x = x, packageName = packageName, wildcardImport = wildcardImport, parsed = parsed)}
|${imports.mkString("\n")}
|
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class ScalametaASTSpec extends AnyFreeSpec {
|import scala.meta.Lit
|import scala.meta.Pat
|import scala.meta.Term
|import scala.meta.transversers._
|import scalafix.Patch
|import scalafix.lint.Diagnostic
|import scalafix.lint.LintSeverity
|import scalafix.v1.SyntacticDocument
|import scalafix.v1.SyntacticRule
|import scalafix.v1.XtensionSeqPatch
|
|class Example extends SyntacticRule("Example") {
| override def fix(implicit doc: SyntacticDocument): Patch = {
Expand Down Expand Up @@ -97,9 +99,11 @@ class ScalametaASTSpec extends AnyFreeSpec {
s"""package package_name
|
|import scala.meta.Term
|import scala.meta.transversers._
|import scalafix.Patch
|import scalafix.v1.SyntacticDocument
|import scalafix.v1.SyntacticRule
|import scalafix.v1.XtensionSeqPatch
|
|class Example extends SyntacticRule("Example") {
| override def fix(implicit doc: SyntacticDocument): Patch = {
Expand Down
2 changes: 2 additions & 0 deletions localServer/src/test/resources/semantic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package fix

import scala.meta.Defn
import scala.meta.Term
import scala.meta.transversers._
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SemanticDocument
import scalafix.v1.SemanticRule
import scalafix.v1.XtensionSeqPatch

class Example extends SemanticRule("Example") {
override def fix(implicit
Expand Down
2 changes: 2 additions & 0 deletions localServer/src/test/resources/syntactic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package fix

import scala.meta.Defn
import scala.meta.Term
import scala.meta.transversers._
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule
import scalafix.v1.XtensionSeqPatch

class Example extends SyntacticRule("Example") {
override def fix(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ abstract class IntegrationTest(
.toList
assert(
diff == List(
("import scala.meta._", "import scala.meta.*")
("import scala.meta._", "import scala.meta.*"),
("import scala.meta.transversers._", "import scala.meta.transversers.*"),
)
)
}
Expand Down

0 comments on commit c9ca076

Please sign in to comment.