Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scalafix 0.14 #225

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ lazy val `scalameta-ast` = projectMatrix
metaVersion := (LocalProject("scalameta-ast-latestJS") / metaVersion).value,
testBuildInfo,
commonLatest,
libraryDependencies += "org.scalameta" %%% "scalameta" % "4.10.2",
libraryDependencies += "org.scalameta" %%% "scalafmt-core" % "3.8.3",
libraryDependencies += "org.scalameta" %%% "scalameta" % "4.12.4.1",
libraryDependencies += "org.scalameta" %%% "scalafmt-core" % "3.8.4",
libraryDependencies += "com.google.inject" % "guice" % "7.0.0" % Test,
Test / resourceGenerators += Def.task {
val v1 = (LocalProject("scalameta-ast-latestJS") / metaTreesSource).value
Expand Down Expand Up @@ -77,7 +77,7 @@ lazy val `scalameta-ast` = projectMatrix
jsProjectSettings,
commonLatest,
libraryDependencies += "org.ekrich" %%% "sconfig" % "1.8.1",
libraryDependencies += ("com.github.xuwei-k" %%% "scalafmt-core" % "3.8.3-fork-2").withSources(),
libraryDependencies += ("com.github.xuwei-k" %%% "scalafmt-core" % "3.8.4-fork-1").withSources(),
)
)

Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/scalameta_ast/AfterExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object AfterExtractor extends AfterExtractorEnable {
E2("Term", "PolyFunction", "After_4_6_0"),
E2("Term", "Try", "After_4_9_9"),
E2("Type", "Apply", "After_4_6_0"),
E2("Type", "Bounds", "After_4_12_3"),
E2("Type", "ContextFunction", "After_4_6_0"),
E2("Type", "Existential", "After_4_9_9"),
E2("Type", "Function", "After_4_6_0"),
Expand Down
225 changes: 219 additions & 6 deletions core/src/test/scala-latest-js/scalameta_ast/ScalametaASTSpec2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,167 @@ class ScalametaASTSpec2 extends AnyFreeSpec {
"ScalametaAST" - {
val main = new ScalametaAST

"convert" in {
val result = main.convert(
src = "val x = ((), null)",
outputType = "syntactic",
packageName = Option("package_name"),
wildcardImport = false,
ruleNameOption = None,
dialect = None,
patch = None,
removeNewFields = true,
initialExtractor = false,
explanation = true,
pathFilter = false,
)
val expect =
s"""package package_name
|
|import scala.meta.Defn
|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 = {
| doc.tree.collect {
| case t @ Defn.Val(
| Nil,
| List(
| Pat.Var(Term.Name("x"))
| ),
| None,
| Term.Tuple(List(
| Lit.Unit(),
| Lit.Null()
| ))
|) =>
| Patch.lint(
| Diagnostic(
| id = "",
| message = "",
| position = t.pos,
| explanation = "",
| severity = LintSeverity.Warning
| )
| )
| }.asPatch
| }
|}
|""".stripMargin
assert(result.result == expect)
}

"import" in {
val result = main.convert(
src = (
"Case",
"Ctor",
"Decl",
"Defn",
"Defn",
"Export",
"Import",
"Importee",
"Init",
"Member",
"Mod",
"Pkg",
"Ref",
"Self",
"Stat",
"Template",
"Type"
).toString,
outputType = "syntactic",
packageName = Option("package_name"),
wildcardImport = false,
ruleNameOption = None,
dialect = None,
patch = Some("empty"),
removeNewFields = true,
initialExtractor = false,
explanation = true,
pathFilter = false,
)
val expect =
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 = {
| doc.tree.collect {
| case t @ Term.Tuple(List(
| Term.Name("Case"),
| Term.Name("Ctor"),
| Term.Name("Decl"),
| Term.Name("Defn"),
| Term.Name("Defn"),
| Term.Name("Export"),
| Term.Name("Import"),
| Term.Name("Importee"),
| Term.Name("Init"),
| Term.Name("Member"),
| Term.Name("Mod"),
| Term.Name("Pkg"),
| Term.Name("Ref"),
| Term.Name("Self"),
| Term.Name("Stat"),
| Term.Name("Template"),
| Term.Name("Type")
|)) =>
| Patch.empty
| }.asPatch
| }
|}
|""".stripMargin
assert(result.result == expect)
}

"Term.ParamClause and ArgClause" in {
val expect =
"""Defn.Def.After_4_7_3(Nil, Term.Name("a"), List(Member.ParamClauseGroup(Type.ParamClause(Nil), List(Term.ParamClause(List(Term.Param(Nil, Term.Name("b"), Some(Type.Name("C")), None)), None)))), None, Term.Apply.After_4_6_0(Term.Name("d"), Term.ArgClause(List(Term.Name("e")), None)))"""
"""Defn.Def.After_4_7_3(
| Nil,
| Term.Name("a"),
| List(
| Member.ParamClauseGroup(
| Type.ParamClause(Nil),
| List(
| Term.ParamClause(List(
| Term.Param(
| Nil,
| Term.Name("b"),
| Some(
| Type.Name("C")
| ),
| None
| )
| ), None)
| )
| )
| ),
| None,
| Term.Apply.After_4_6_0(
| Term.Name("d"),
| Term.ArgClause(List(
| Term.Name("e")
| ), None)
| )
|)""".stripMargin
val result = main.convert(
src = "def a(b: C) = d(e)",
outputType = "",
Expand All @@ -32,7 +190,20 @@ class ScalametaASTSpec2 extends AnyFreeSpec {

"Term.If" in {
val expect =
"""Term.If.After_4_4_0(Term.Name("a"), Term.Name("b"), Term.If.After_4_4_0(Term.Name("x"), Term.Name("y"), Term.Select(Term.Name("z"), Term.Name("f")), Nil), Nil)"""
"""Term.If.After_4_4_0(
| Term.Name("a"),
| Term.Name("b"),
| Term.If.After_4_4_0(
| Term.Name("x"),
| Term.Name("y"),
| Term.Select(
| Term.Name("z"),
| Term.Name("f")
| ),
| Nil
| ),
| Nil
|)""".stripMargin
val result = main.convert(
src = """if a then b else (if(x) y else z.f)""",
outputType = "",
Expand All @@ -51,7 +222,19 @@ class ScalametaASTSpec2 extends AnyFreeSpec {

"Term.Match" in {
val expect =
"""Term.Match.After_4_9_9(Term.Name("a"), Term.CasesBlock(List(Case(Pat.Var(Term.Name("b")), None, Term.Block(Nil)))), List(Mod.Inline()))"""
"""Term.Match.After_4_9_9(
| Term.Name("a"),
| Term.CasesBlock(List(
| Case(
| Pat.Var(Term.Name("b")),
| None,
| Term.Block(Nil)
| )
| )),
| List(
| Mod.Inline()
| )
|)""".stripMargin
val result = main.convert(
src = """inline a match { case b => }""",
outputType = "",
Expand Down Expand Up @@ -84,7 +267,18 @@ class ScalametaASTSpec2 extends AnyFreeSpec {
)

val expect =
"""Defn.Type.After_4_6_0(Nil, Type.Name("A"), Type.ParamClause(Nil), Type.Name("B"), Type.Bounds(None, None))"""
"""Defn.Type.After_4_6_0(
| Nil,
| Type.Name("A"),
| Type.ParamClause(Nil),
| Type.Name("B"),
| Type.Bounds.After_4_12_3(
| None,
| None,
| Nil,
| Nil
| )
|)""".stripMargin
assert(result.result == expect)
}

Expand All @@ -104,8 +298,27 @@ class ScalametaASTSpec2 extends AnyFreeSpec {
)

val expect =
"""Defn.Class.After_4_6_0(Nil, Type.Name("A"), Type.ParamClause(Nil), Ctor.Primary.After_4_6_0(Nil, Name.Anonymous(), Nil), Template.After_4_9_9(None, Nil, Template.Body(None, Nil), List(Type.Name("B"))))"""

"""Defn.Class.After_4_6_0(
| Nil,
| Type.Name("A"),
| Type.ParamClause(Nil),
| Ctor.Primary.After_4_6_0(
| Nil,
| Name.Anonymous(),
| Nil
| ),
| Template.After_4_9_9(
| None,
| Nil,
| Template.Body(
| None,
| Nil
| ),
| List(
| Type.Name("B")
| )
| )
|)""".stripMargin
assert(result.result == expect)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,109 @@ class ScalametaASTSpec2 extends AnyFreeSpec {
"ScalametaAST" - {
val main = new ScalametaAST

"convert" in {
val result = main.convert(
src = "val x = ((), null)",
outputType = "syntactic",
packageName = Option("package_name"),
wildcardImport = false,
ruleNameOption = None,
dialect = None,
patch = None,
removeNewFields = true,
initialExtractor = false,
explanation = true,
pathFilter = false,
)
val expect =
s"""package package_name
|
|import scala.meta.Defn
|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 = {
| doc.tree.collect {
| case t @ Defn.Val(Nil, List(Pat.Var(Term.Name("x"))), None, Term.Tuple(List(Lit.Unit(), Lit.Null()))) =>
| Patch.lint(
| Diagnostic(
| id = "",
| message = "",
| position = t.pos,
| explanation = "",
| severity = LintSeverity.Warning
| )
| )
| }.asPatch
| }
|}
|""".stripMargin
assert(result.result == expect)
}

"import" in {
val result = main.convert(
src = (
"Case",
"Ctor",
"Decl",
"Defn",
"Defn",
"Export",
"Import",
"Importee",
"Init",
"Member",
"Mod",
"Pkg",
"Ref",
"Self",
"Stat",
"Template",
"Type"
).toString,
outputType = "syntactic",
packageName = Option("package_name"),
wildcardImport = false,
ruleNameOption = None,
dialect = None,
patch = Some("empty"),
removeNewFields = true,
initialExtractor = false,
explanation = true,
pathFilter = false,
)
val expect =
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 = {
| doc.tree.collect {
| case t @ Term.Tuple(List(Term.Name("Case"), Term.Name("Ctor"), Term.Name("Decl"), Term.Name("Defn"), Term.Name("Defn"), Term.Name("Export"), Term.Name("Import"), Term.Name("Importee"), Term.Name("Init"), Term.Name("Member"), Term.Name("Mod"), Term.Name("Pkg"), Term.Name("Ref"), Term.Name("Self"), Term.Name("Stat"), Term.Name("Template"), Term.Name("Type"))) =>
| Patch.empty
| }.asPatch
| }
|}
|""".stripMargin
assert(result.result == expect)
}

"Term.If" in {
Seq[(String, List[TestArg])](
"""Term.If.Initial(Term.Name("a"), Term.Name("b"), Term.If.Initial(Term.Name("x"), Term.Name("y"), Term.Select(Term.Name("z"), Term.Name("f"))))"""
Expand Down
Loading
Loading