Skip to content

Upgrade scalafmt to 3.0.5 #585

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

Merged
merged 1 commit into from
Sep 27, 2021
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
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.0.2
version = 3.0.5
project.git = true
style = Scala.js
project.includeFilters = ["src/main/scala/org/scalajs/.*\\.scala"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class DefaultFacadeArgs extends SemanticRule("DefaultFacadeArgs") {
doc.tree.collect {

case Defn.Def(mods, _, _, paramss, _, body) if Util.isJsNative(body) =>

// https://github.com/scala-js/scala-js/issues/4553
// `js.native` as default arg doesn't compile for top-level method facades.
if (Util.isJSGlobal(mods)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
case a: Defn.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
case a: Defn.Trait => process(a.mods, a.symbol, a.templ, ScopeType.Trait)
case a: Pkg.Object => process(a.mods, a.symbol, a.templ, ScopeType.Object)
case _ =>
case _ =>
}

Patch.empty
}

private def process(parentMods: List[Mod], sym: Symbol, body: Template, typ: ScopeType)(implicit doc: SemanticDocument): Unit = {
private def process(parentMods: List[Mod], sym: Symbol, body: Template, typ: ScopeType)(
implicit doc: SemanticDocument): Unit = {
// Skip non-public scopes
val info = sym.info.get
if (!info.isPublic && !info.isPackageObject)
Expand All @@ -41,10 +42,10 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
_.filter {
case Mod.Annot(Init(tpe, _, List(List(_, ver)))) if tpe.toString == "deprecated" =>
set(
ver match {
case Lit.String(s) => s
case term => term.toString
}
ver match {
case Lit.String(s) => s
case term => term.toString
}
)
false
case _ => true
Expand All @@ -54,10 +55,10 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
var scopeDeprecatedVer = Option.empty[String]
inspectAnnotationsFn(v => scopeDeprecatedVer = Some(v))(parentMods)

val parents = Util.parents(sym).iterator.map(Util.typeSymbol).toList
val parents = Util.parents(sym).iterator.map(Util.typeSymbol).toList
val domParents = parents.iterator.filter(isScalaJsDom).toSet
val isJsType = parents.exists(isScalaJs)
val s = state.register(sym, isJsType, typ, domParents, scopeDeprecatedVer)
val isJsType = parents.exists(isScalaJs)
val s = state.register(sym, isJsType, typ, domParents, scopeDeprecatedVer)

def letsSeeHowLazyWeCanBeLol(t: Tree): Unit = {
// Skip non-public members
Expand All @@ -77,17 +78,17 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
var deprecatedVer = Option.empty[String]
val inspectAnnotations = inspectAnnotationsFn(v => deprecatedVer = Some(v))
t2 match {
case Decl.Def(mods, name, tparams, paramss, tpe) => t2 = Decl.Def(inspectAnnotations(mods), name, tparams, paramss, tpe)
case Decl.Val(mods, pats, tpe) => t2 = Decl.Val(inspectAnnotations(mods), pats, tpe)
case Decl.Var(mods, pats, tpe) => t2 = Decl.Var(inspectAnnotations(mods), pats, tpe)
case Defn.Type(mods, names, params, tpe) => t2 = Defn.Type(inspectAnnotations(mods), names, params, tpe)
case _ =>
case Decl.Def(mods, name, tparams, paramss, tpe) =>
t2 = Decl.Def(inspectAnnotations(mods), name, tparams, paramss, tpe)
case Decl.Val(mods, pats, tpe) => t2 = Decl.Val(inspectAnnotations(mods), pats, tpe)
case Decl.Var(mods, pats, tpe) => t2 = Decl.Var(inspectAnnotations(mods), pats, tpe)
case Defn.Type(mods, names, params, tpe) => t2 = Defn.Type(inspectAnnotations(mods), names, params, tpe)
case _ =>
}

// Generate member desc
val desc =
t2
.toString
t2.toString
.replace('\n', ' ')
.replace("=", " = ")
.replace("@inline ", "")
Expand Down Expand Up @@ -131,10 +132,10 @@ class GenerateApiReport extends SemanticRule("GenerateApiReport") {
}

private def saveReport(): Unit = {
val scalaVer = Util.scalaSeriesVer.replace('.', '_')
val scalaVer = Util.scalaSeriesVer.replace('.', '_')
val projectRoot = System.getProperty("user.dir")
val reportFile = Paths.get(s"$projectRoot/api-reports/$scalaVer.txt")
val api = state.result().iterator.map(_.stripPrefix("org/scalajs/dom/")).mkString("\n")
val reportFile = Paths.get(s"$projectRoot/api-reports/$scalaVer.txt")
val api = state.result().iterator.map(_.stripPrefix("org/scalajs/dom/")).mkString("\n")

val content =
s"""|scala-js-dom API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ final class MutableState {

private[this] val scopes = mutable.Map.empty[Symbol, Scope]

def register(sym : Symbol,
isJsType : Boolean,
scopeType : ScopeType,
parents : Set[Symbol],
deprecatedVer: Option[String]): Scope = synchronized {
def register(sym: Symbol, isJsType: Boolean, scopeType: ScopeType, parents: Set[Symbol],
deprecatedVer: Option[String]): Scope = synchronized {
scopes.get(sym) match {
case None =>
val s = Scope(sym)(scopeType, parents)
Expand Down Expand Up @@ -70,11 +67,11 @@ final class MutableState {
// Pass 2
for (root <- scopes.valuesIterator) {
val scopeName = root.symbol.value.stripSuffix("#").stripSuffix(".")
val flagLang = if (root.isJsType) "J" else "S"
val flagTyp = root.scopeType.id
val flags = flagLang + flagTyp
val prefix = s"$scopeName[$flags] "
val scopeKey = s"$scopeName$sortHack[$flags"
val flagLang = if (root.isJsType) "J" else "S"
val flagTyp = root.scopeType.id
val flags = flagLang + flagTyp
val prefix = s"$scopeName[$flags] "
val scopeKey = s"$scopeName$sortHack[$flags"

var membersFound = false
for {
Expand Down Expand Up @@ -102,15 +99,14 @@ object MutableState {
var global: MutableState = null

sealed abstract class ScopeType(final val id: String)

object ScopeType {
case object Class extends ScopeType("C")
case object Trait extends ScopeType("T")
case object Object extends ScopeType("O")
}

final case class Scope(symbol: Symbol)
(val scopeType: ScopeType,
val parents: Set[Symbol]) {
final case class Scope(symbol: Symbol)(val scopeType: ScopeType, val parents: Set[Symbol]) {

private[MutableState] val directMembers = mutable.Set.empty[Member]
private[MutableState] var isJsType = false
Expand Down
15 changes: 7 additions & 8 deletions scalafix/src/main/scala/org/scalajs/dom/scalafix/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Util {
def isJSGlobal(mods: List[Mod]): Boolean =
mods.exists {
case Mod.Annot(Init(Type.Name("JSGlobal"), _, _)) => true
case _ => false
case _ => false
}

def isJsNative(t: Term): Boolean = {
Expand Down Expand Up @@ -95,10 +95,10 @@ object Util {

def typeSymbol(t: SemanticType): Symbol =
t match {
case x: TypeRef => x.symbol
case x: SingleType => x.symbol
case x: ThisType => x.symbol
case x: SuperType => x.symbol
case x: TypeRef => x.symbol
case x: SingleType => x.symbol
case x: ThisType => x.symbol
case x: SuperType => x.symbol
// case x: ConstantType => xxx // (constant) =>
// case x: IntersectionType => xxx // (types) =>
// case x: UnionType => xxx // (types) =>
Expand All @@ -110,8 +110,7 @@ object Util {
// case x: ByNameType => xxx // (tpe) =>
// case x: RepeatedType => xxx // (tpe) =>
// case NoType => Symbol.None
case _ => Symbol.None
case _ => Symbol.None
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object AsyncTesting {
}

implicit final class AsyncFutureOps[A](private val self: Future[A]) extends AnyVal {

def tap(f: A => Any): Future[A] =
self.map { a => f(a); a }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object IdbTest {

for {
john <- getFirstName(getJohn)
bob <- getFirstName(getBob)
bob <- getFirstName(getBob)
} yield {
assertEquals("John", john)
assertEquals("Bob", bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ trait SharedTests {

// This tests that ops are always implicitly available, no imports required
@Test final def DOMTokenListOpsTest(): Unit = {
org.scalajs.dom.document.querySelectorAll("*")
org.scalajs.dom.document
.querySelectorAll("*")
.iterator
.collect { case e: org.scalajs.dom.html.Element => e }
.map(_.classList.mkString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.util.Success
final class Client(worker: Worker) {
import Protocol._

private var preInit = new js.Array[Message]
private var preInit = new js.Array[Message]
private var promises = new js.Array[Promise[String]]

worker.onmessage = (e: MessageEvent) => {
Expand All @@ -22,8 +22,8 @@ final class Client(worker: Worker) {

def send(cmd: WebWorkerCmd): Future[String] = {
val id = promises.length
val p = Promise[String]()
val m = Message(id, cmd.id)
val p = Promise[String]()
val m = Message(id, cmd.id)
promises.push(p)
if (preInit eq null)
worker.postMessage(m)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.scalajs.js

object Protocol {

type MsgId = Int
type MsgId = Int
type Message = js.Tuple2[MsgId, String]

def Message(id: MsgId, data: String): Message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ object Server extends ServerResponses {
val ww = DedicatedWorkerGlobalScope.self

ww.onmessage = (e: MessageEvent) => {
val msgIn = e.data.asInstanceOf[Message]
val id = msgIn._1
val cmdId = msgIn._2
val cmd = WebWorkerCmd.byId(cmdId)
val msgIn = e.data.asInstanceOf[Message]
val id = msgIn._1
val cmdId = msgIn._2
val cmd = WebWorkerCmd.byId(cmdId)
respond(cmd).onComplete { t =>
val output = t.getOrElse(t.failed.get.toString)
val msgOut = Message(id, output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ sealed abstract class WebWorkerCmd {

object WebWorkerCmd {

case object SayHello extends WebWorkerCmd
case object SayHello extends WebWorkerCmd
case object TestConsole extends WebWorkerCmd
case object TestIdb extends WebWorkerCmd
case object TestIdb extends WebWorkerCmd

def byId(id: String): WebWorkerCmd =
id match {
Expand Down Expand Up @@ -55,6 +55,7 @@ trait ServerResponses {
Future(s)

private implicit class AsyncOps(r: AsyncResult) {

def andReturn(s: String): Future[String] =
r.map { t =>
t.get
Expand Down