diff --git a/.scalafmt.conf b/.scalafmt.conf index 0d45a5ae4..668e98f87 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -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"] diff --git a/scalafix/src/main/scala/org/scalajs/dom/scalafix/DefaultFacadeArgs.scala b/scalafix/src/main/scala/org/scalajs/dom/scalafix/DefaultFacadeArgs.scala index 7f0c1c57b..a69085bce 100644 --- a/scalafix/src/main/scala/org/scalajs/dom/scalafix/DefaultFacadeArgs.scala +++ b/scalafix/src/main/scala/org/scalajs/dom/scalafix/DefaultFacadeArgs.scala @@ -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)) { diff --git a/scalafix/src/main/scala/org/scalajs/dom/scalafix/GenerateApiReport.scala b/scalafix/src/main/scala/org/scalajs/dom/scalafix/GenerateApiReport.scala index 138921a3b..512873f4f 100644 --- a/scalafix/src/main/scala/org/scalajs/dom/scalafix/GenerateApiReport.scala +++ b/scalafix/src/main/scala/org/scalajs/dom/scalafix/GenerateApiReport.scala @@ -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) @@ -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 @@ -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 @@ -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 ", "") @@ -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 diff --git a/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala b/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala index 7e0882f2e..0ecbdbd41 100644 --- a/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala +++ b/scalafix/src/main/scala/org/scalajs/dom/scalafix/MutableState.scala @@ -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) @@ -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 { @@ -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 diff --git a/scalafix/src/main/scala/org/scalajs/dom/scalafix/Util.scala b/scalafix/src/main/scala/org/scalajs/dom/scalafix/Util.scala index 31874c1e8..ad4d1a0c3 100644 --- a/scalafix/src/main/scala/org/scalajs/dom/scalafix/Util.scala +++ b/scalafix/src/main/scala/org/scalajs/dom/scalafix/Util.scala @@ -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 = { @@ -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) => @@ -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 } - -} \ No newline at end of file +} diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala index 7d723804d..1c523c11e 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/AsyncTesting.scala @@ -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 } diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala index c3952e4f3..b48d34bbc 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/IdbTest.scala @@ -73,7 +73,7 @@ object IdbTest { for { john <- getFirstName(getJohn) - bob <- getFirstName(getBob) + bob <- getFirstName(getBob) } yield { assertEquals("John", john) assertEquals("Bob", bob) diff --git a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala index 456b34102..789e44dc5 100644 --- a/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala +++ b/tests-shared/src/main/scala/org/scalajs/dom/tests/shared/SharedTests.scala @@ -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) diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Client.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Client.scala index 55ad9c6bd..b86bc865f 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Client.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Client.scala @@ -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) => { @@ -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) diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Protocol.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Protocol.scala index 6f6829468..9d9fc0ae6 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Protocol.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Protocol.scala @@ -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 = diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala index f3bad138e..eaa241f2d 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/Server.scala @@ -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) diff --git a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala index 02aa7a1c8..7a9abaee1 100644 --- a/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala +++ b/tests-webworker/src/main/scala/org/scalajs/dom/tests/webworker/WebWorkerTests.scala @@ -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 { @@ -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