Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Mar 10, 2024
1 parent f3d954a commit 36ec3d5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ lazy val localServer = project.settings(
commonSettings,
run / fork := true,
run / baseDirectory := (LocalRootProject / baseDirectory).value,
Test / testOptions += Tests.Argument("-oD"),
Test / testOptions += Tests.Argument("-oDF"),
Test / test := (Test / test).dependsOn(LocalRootProject / copyFilesFull).value,
Test / testOptions ++= {
if (scala.util.Properties.isMac) {
Expand Down
3 changes: 1 addition & 2 deletions localServer/src/test/resources/raw.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Defn.Def(
Defn.Def.After_4_7_3(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
)
Expand Down
15 changes: 2 additions & 13 deletions localServer/src/test/resources/semantic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package fix
import scala.meta.Defn
import scala.meta.Term
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SemanticDocument
import scalafix.v1.SemanticRule

Expand All @@ -13,23 +11,14 @@ class Example extends SemanticRule("Example") {
doc: SemanticDocument
): Patch = {
doc.tree.collect {
case t @ Defn.Def(
case t @ Defn.Def.After_4_7_3(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
Patch.replaceTree(t, "")
}.asPatch
}
}
Expand Down
15 changes: 2 additions & 13 deletions localServer/src/test/resources/syntactic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package fix
import scala.meta.Defn
import scala.meta.Term
import scalafix.Patch
import scalafix.lint.Diagnostic
import scalafix.lint.LintSeverity
import scalafix.v1.SyntacticDocument
import scalafix.v1.SyntacticRule

Expand All @@ -13,23 +11,14 @@ class Example extends SyntacticRule("Example") {
doc: SyntacticDocument
): Patch = {
doc.tree.collect {
case t @ Defn.Def(
case t @ Defn.Def.After_4_7_3(
Nil,
Term.Name("a"),
Nil,
Nil,
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
Patch.replaceTree(t, "")
}.asPatch
}
}
Expand Down
25 changes: 14 additions & 11 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
}

private def getById(page: Page, role: AriaRole, id: String): Locator = {
page.getByRole(role).all().asScala.find(_.getAttribute("id") == id).getOrElse(sys.error("not found"))
page.getByRole(role).all().asScala.find(_.getAttribute("id") == id).getOrElse(sys.error(s"not found $id"))
}

private def getTextboxById(page: Page, id: String): Locator =
Expand Down Expand Up @@ -104,7 +104,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
.getByRole(AriaRole.RADIO)
.all()
.asScala
.find(_.getAttribute("id") == outputType)
.find(_.getAttribute("value") == outputType)
.getOrElse(sys.error(s"not found ${outputType}"))
.check()
}
Expand All @@ -114,23 +114,24 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
}

"change input" in withBrowser { page =>
changeOutputType(page, "raw")
setInput(page, "class A")
val expect = Seq(
"""Defn.Class(""",
"""Defn.Class.After_4_6_0(""",
""" Nil,""",
""" Type.Name("A"),""",
""" Nil,""",
""" Ctor.Primary(Nil, Name(""), Nil),""",
""" Template(""",
""" Type.ParamClause(Nil),""",
""" Ctor.Primary""",
""" .After_4_6_0(Nil, Name.Anonymous(), Nil),""",
""" Template.After_4_4_0(""",
""" Nil,""",
""" Nil,""",
""" Self(Name(""), None),""",
""" Self(Name.Anonymous(), None),""",
""" Nil,""",
""" Nil""",
""" )""",
""")""",
"",
).mkString("\n")
).mkString("", "\n", "\n")
assert(output(page).textContent() == expect)
}

Expand Down Expand Up @@ -207,9 +208,9 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A

"patch" in withBrowser { page =>
changeOutputType(page, "syntactic")
assert(output(page).textContent().contains("LintSeverity.Warning"))
page.selectOption("select#patch", "replace")
assert(output(page).textContent().contains("Patch.replace"))
page.selectOption("select#patch", "warn")
assert(output(page).textContent().contains("LintSeverity.Warning"))
page.selectOption("select#patch", "empty")
assert(output(page).textContent().contains("Patch.empty"))
}
Expand Down Expand Up @@ -248,6 +249,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A

"output" in withBrowser { page =>
def render(): Unit = inputElem(page).press("\n")

changeOutputType(page, "syntactic")
wildcardImport(page).check()
render()
Expand Down Expand Up @@ -278,6 +280,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
}

"Initial extractor" in withBrowser { page =>
page.selectOption("select#scalameta", "scalafix")
changeOutputType(page, "raw")
setScalafmtConfig(
page,
Expand Down
32 changes: 27 additions & 5 deletions sources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ const App = () => {
});
}

const disableScalafixRuleTemplateInput = outputType === "raw" || outputType === "tokens";
const disableScalafixRuleTemplateInput =
outputType === "raw" || outputType === "tokens";

return html` <div class="container mw-100">
<details open ontoggle="${(e) => changeDetails(e)}">
Expand All @@ -200,6 +201,7 @@ const App = () => {
<input
type="checkbox"
name="wildcard_import"
id="wildcard_import"
disabled=${disableScalafixRuleTemplateInput}
checked=${wildcardImport}
onChange=${(e) => setWildcardImport(e.target.checked)}
Expand All @@ -211,6 +213,8 @@ const App = () => {
type="checkbox"
id="remove_new_fields"
name="remove_new_fields"
checked=${removeNewFields}
onChange=${(e) => setRemoveNewFields(e.target.checked)}
/>
<label for="remove_new_fields"
>remove <code>@newField</code> for
Expand All @@ -222,6 +226,9 @@ const App = () => {
type="checkbox"
id="initial_extractor"
name="initial_extractor"
checked=${initialExtractor}
onChange=${(e) => setInitialExtractor(e.target.checked)}
/>
/>
<label for="initial_extractor"
><code>Initial</code> extractor</label
Expand All @@ -233,13 +240,18 @@ const App = () => {
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary" onclick=${() => formatInput()}>
<button
class="btn btn-primary"
onclick=${() => formatInput()}
id="format_input"
>
format input scala code
</button>
</div>
<div class="col">
<button
class="btn btn-primary"
id="clear_local_storage"
onclick=${() => localStorage.clear()}
>
clear local storage
Expand Down Expand Up @@ -298,6 +310,7 @@ const App = () => {
<label for="dialect">dialect</label>
<select
name="dialect"
id="dialect"
value=${dialect}
onChange=${(e) => setDialect(e.target.value)}
>
Expand All @@ -319,6 +332,7 @@ const App = () => {
<label for="scalameta">scalameta version</label>
<select
name="scalameta"
id="scalameta"
value=${scalameta}
onChange=${(e) => setScalameta(e.target.value)}
>
Expand Down Expand Up @@ -363,6 +377,7 @@ const App = () => {
>
<select
name="patch"
id="patch"
value=${patch}
disabled=${disableScalafixRuleTemplateInput}
onChange=${(e) => setPatch(e.target.value)}
Expand All @@ -384,13 +399,16 @@ const App = () => {
<div class="col">
<textarea
style="width: 100%; height: 800px"
id="input_scala"
onkeyup=${(e) => setInputScala(e.target.value)}
onChange=${(e) => setInputScala(e.target.value)}
value=${inputScala}
></textarea>
</div>
<div class="col">
<pre>
<code
id="output_scala"
class="language-scala hljs"
dangerouslySetInnerHTML=${{ __html: result }}
style="width: 100%; height: 800px; background-color:rgb(233, 233, 233);"
Expand All @@ -407,9 +425,13 @@ const App = () => {
>scalafmt config</a
>
</p>
<textarea style="width: 100%; height: 200px">
${scalafmtConfig}</textarea
>
<textarea
style="width: 100%; height: 200px"
id="scalafmt"
onkeyup=${(e) => setScalafmtConfig(e.target.value)}
onChange=${(e) => setScalafmtConfig(e.target.value)}
value=${scalafmtConfig}
></textarea>
</div>
</div>
<div class="row" id="footer"></div>
Expand Down

0 comments on commit 36ec3d5

Please sign in to comment.