Skip to content

Commit

Permalink
delete jquery. use preact
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Mar 10, 2024
1 parent 135145f commit 134c2fb
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 509 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
44 changes: 26 additions & 18 deletions core/src/main/js/scalameta_ast/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,32 @@ object Main {
removeNewFields: Boolean,
initialExtractor: Boolean,
): js.Object = {
val output =
new ScalametaAST().convert(
src = source,
format = format,
scalafmtConfig = hoconToMetaConfig(scalafmtConfJsonStr),
outputType = outputType,
packageName = Option(packageName).filter(_.trim.nonEmpty),
wildcardImport = wildcardImport,
ruleNameOption = Option(ruleName).filter(_.trim.nonEmpty),
dialect = Option(dialect).filter(_.trim.nonEmpty),
patch = Option(patch).filter(_.trim.nonEmpty),
removeNewFields = removeNewFields,
initialExtractor = initialExtractor,
)
new js.Object {
var ast = output.ast
var astBuildMs = output.astBuildMs.toDouble
var formatMs = output.formatMs.toDouble
try {
val output =
new ScalametaAST().convert(
src = source,
format = format,
scalafmtConfig = hoconToMetaConfig(scalafmtConfJsonStr),
outputType = outputType,
packageName = Option(packageName).filter(_.trim.nonEmpty),
wildcardImport = wildcardImport,
ruleNameOption = Option(ruleName).filter(_.trim.nonEmpty),
dialect = Option(dialect).filter(_.trim.nonEmpty),
patch = Option(patch).filter(_.trim.nonEmpty),
removeNewFields = removeNewFields,
initialExtractor = initialExtractor,
)
new js.Object {
var ast = output.ast
var astBuildMs = output.astBuildMs.toDouble
var formatMs = output.formatMs.toDouble
}
} catch {
case e: Throwable =>
new js.Object {
var error = e
var errorString: String = e.toString
}
}
}

Expand Down
12 changes: 1 addition & 11 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 @@ -20,15 +18,7 @@ class Example extends SemanticRule("Example") {
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
Patch.replaceTree(t, "")
}.asPatch
}
}
Expand Down
12 changes: 1 addition & 11 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 @@ -20,15 +18,7 @@ class Example extends SyntacticRule("Example") {
None,
Term.Name("b")
) =>
Patch.lint(
Diagnostic(
id = "",
message = "",
position = t.pos,
explanation = "",
severity = LintSeverity.Warning
)
)
Patch.replaceTree(t, "")
}.asPatch
}
}
Expand Down
10 changes: 5 additions & 5 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
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,6 +114,7 @@ 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.After_4_6_0(""",
Expand All @@ -130,8 +131,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
""" Nil""",
""" )""",
""")""",
"",
).mkString("\n")
).mkString("", "\n", "\n")
assert(output(page).textContent() == expect)
}

Expand Down Expand Up @@ -208,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
194 changes: 1 addition & 193 deletions sources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
<head>
<meta charset="UTF-8" />
<title>scalameta-ast</title>
<script
type="text/javascript"
src="https://code.jquery.com/jquery-3.7.1.min.js"
></script>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css"
/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/scala.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/highlightjs-copy.min.js"></script>
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/highlightjs-copy.min.css"
Expand All @@ -40,191 +33,6 @@
integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3"
crossorigin="anonymous"
></script>
<div class="container mw-100">
<details open id="header_all_scalafix_config">
<summary>close header</summary>
<div class="row">
<div class="col-5">
<pre id="info" class="alert" style="height: 100px"></pre>
</div>
<div class="col-3">
<div class="row">
<div>
<input type="checkbox" id="format" checked />
<label for="format">format output by scalafmt</label>
</div>
<div>
<input
type="checkbox"
id="wildcard_import"
name="wildcard_import"
/>
<label for="wildcard_import">wildcard import</label>
</div>
<div>
<input
type="checkbox"
id="remove_new_fields"
name="remove_new_fields"
/>
<label for="remove_new_fields"
>remove <code>@newField</code> for
<code>unapply</code> compatibility</label
>
</div>
<div>
<input
type="checkbox"
id="initial_extractor"
name="initial_extractor"
/>
<label for="initial_extractor"
><code>Initial</code> extractor</label
>
</div>
</div>
<div class="row">
<p></p>
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary" id="format_input">
format input scala code
</button>
</div>
<div class="col">
<button class="btn btn-primary" id="clear_local_storage">
clear local storage
</button>
</div>
</div>
</div>
<div class="col-2">
<div class="row">
<fieldset>
<legend>output type</legend>
<div>
<input type="radio" id="raw" name="output_type" value="raw" />
<label for="raw">Raw Scalameta</label>
</div>
<div>
<input
type="radio"
id="syntactic"
name="output_type"
value="syntactic"
/>
<label for="syntactic">Scalafix SyntacticRule</label>
</div>
<div>
<input
type="radio"
id="semantic"
name="output_type"
value="semantic"
/>
<label for="semantic">Scalafix SemanticRule</label>
</div>
<div>
<input
type="radio"
id="tokens"
name="output_type"
value="tokens"
/>
<label for="tokens">Tokens</label>
</div>
</fieldset>
</div>
<div class="row">
<div>
<label for="dialect">dialect</label>
<select name="dialect" id="dialect">
<option value="Auto">Auto</option>
<option value="Scala3">Scala3</option>
<option value="Scala213Source3">Scala213Source3</option>
<option value="Scala213">Scala213</option>
<option value="Scala212Source3">Scala212Source3</option>
<option value="Scala212">Scala212</option>
<option value="Scala211">Scala211</option>
<option value="Scala210">Scala210</option>
</select>
</div>
</div>
</div>
<div class="col-2">
<div class="row">
<div>
<label for="scalameta">scalameta version</label>
<select name="scalameta" id="scalameta">
<option id="scalameta_scalafix_compat" value="scalafix">
scalafix 0.10.x compatible
</option>
<option id="scalameta_latest" value="latest">
scalafix 0.11.x compatible
</option>
</select>
</div>
</div>
<div class="row">
<div>
<label for="package">package</label>
<input type="text" id="package" maxlength="256" />
</div>
</div>
<div class="row">
<div>
<label for="rule_name">rule name</label>
<input type="text" id="rule_name" maxlength="128" />
</div>
</div>
<div class="row">
<div>
<label for="patch"
><a
target="_blank"
href="https://scalacenter.github.io/scalafix/docs/developers/patch.html"
>patch</a
></label
>
<select name="patch" id="patch">
<option value="warn">lint warn</option>
<option value="error">lint error</option>
<option value="info">lint info</option>
<option value="replace">replace</option>
<option value="left">add left</option>
<option value="right">add right</option>
<option value="empty">empty</option>
</select>
</div>
</div>
</div>
</div>
</details>
<div class="row">
<div class="col">
<textarea
id="input_scala"
style="width: 100%; height: 800px"
></textarea>
</div>
<div class="col">
<pre><code class="language-scala" id="output_scala" style="width: 100%; height: 800px; background-color:rgb(233, 233, 233);"></code></pre>
</div>
</div>
<div class="row">
<div class="col">
<p>
<a
href="https://scalameta.org/scalafmt/docs/configuration.html"
target="_blank"
>scalafmt config</a
>
</p>
<textarea id="scalafmt" style="width: 100%; height: 200px"></textarea>
</div>
</div>
<div class="row" id="footer"></div>
</div>
<div id="root"></div>
</body>
</html>
Loading

0 comments on commit 134c2fb

Please sign in to comment.