Skip to content

Commit

Permalink
Check that conversions to scalajs-dom refers to existing types, and v…
Browse files Browse the repository at this point in the history
…erify number of type parameters.
  • Loading branch information
oyvindberg committed Dec 15, 2021
1 parent 97e942a commit b3efa41
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.scalablytyped.converter.internal.scalajs
package flavours

object ReportMissingScalaJsDomTranslations extends App {
val conversions = new ScalaJsDomNames(new QualifiedName.StdNames(Name.std)).All
val conversionTarget = conversions.map(_.to).toSet
val ScalaJsDom = QualifiedName("org.scalajs.dom")
val missing = ScalaJsClasses.ScalaJsTypes.collect {
case (qname, _)
if qname.startsWith(ScalaJsDom) &&
!conversionTarget(qname) &&
!qname.parts.contains(Name("raw")) &&
!qname.parts.contains(Name("experimental")) &&
!qname.parts.contains(Name("crypto")) &&
!qname.parts.contains(Name("svg")) &&
!qname.parts.contains(Name("html")) &&
!qname.parts.contains(Name("idb")) &&
!qname.parts(qname.parts.length - 2).unescaped.head.isUpper =>
qname
}

missing.toList.sortBy(_.parts).foreach(qname => println(qname.parts.map(_.unescaped).mkString(".")))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.scalablytyped.converter.internal.scalajs
package flavours

class ScalaJsDomNamesTest extends org.scalatest.funsuite.AnyFunSuite {
test("check that scalajs-dom names exist and matches expectations") {
val conversions = new ScalaJsDomNames(new QualifiedName.StdNames(Name.std)).All
conversions.foreach { conversion =>
ScalaJsClasses.ScalaJsTypes(conversion.to) match {
case cls: ClassTree =>
if (conversion.tparams.length != cls.tparams.length)
fail(s"Conversion $conversion should have had ${cls.tparams.length} tparams ")

case ta: TypeAliasTree =>
if (conversion.tparams.length != ta.tparams.length)
fail(s"Conversion $conversion should have had ${ta.tparams.length} tparams ")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.scalablytyped.converter.internal
package scalajs
package flavours

import org.scalablytyped.converter.internal.scalajs.CastConversion.TParam._1
import org.scalablytyped.converter.internal.scalajs.CastConversion.TParam

class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {

Expand All @@ -26,7 +26,7 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("AnalyserNode"), QualifiedName("org.scalajs.dom.AnalyserNode")),
CastConversion(stdNames.lib + Name("AnimationEvent"), QualifiedName("org.scalajs.dom.AnimationEvent")),
CastConversion(stdNames.lib + Name("ApplicationCache"), QualifiedName("org.scalajs.dom.ApplicationCache")),
CastConversion(stdNames.lib + Name("Array"), QualifiedName("scala.scalajs.js.Array"), _1),
CastConversion(stdNames.lib + Name("Array"), QualifiedName("scala.scalajs.js.Array"), TParam._1),
CastConversion(stdNames.lib + Name("ArrayBuffer"), QualifiedName("scala.scalajs.js.typedarray.ArrayBuffer")),
CastConversion(stdNames.lib + Name("ArrayBufferView"), QualifiedName("scala.scalajs.js.typedarray.ArrayBufferView")),
CastConversion(stdNames.lib + Name("Attr"), QualifiedName("org.scalajs.dom.Attr")),
Expand Down Expand Up @@ -146,7 +146,7 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("HTMLBodyElement"), QualifiedName("org.scalajs.dom.HTMLBodyElement")),
CastConversion(stdNames.lib + Name("HTMLButtonElement"), QualifiedName("org.scalajs.dom.HTMLButtonElement")),
CastConversion(stdNames.lib + Name("HTMLCanvasElement"), QualifiedName("org.scalajs.dom.HTMLCanvasElement")),
CastConversion(stdNames.lib + Name("HTMLCollection"), QualifiedName("org.scalajs.dom.HTMLCollection")),
CastConversion(stdNames.lib + Name("HTMLCollection"), QualifiedName("org.scalajs.dom.HTMLCollection"), TParam._1),
CastConversion(stdNames.lib + Name("HTMLDListElement"), QualifiedName("org.scalajs.dom.HTMLDListElement")),
CastConversion(stdNames.lib + Name("HTMLDataListElement"), QualifiedName("org.scalajs.dom.HTMLDataListElement")),
CastConversion(stdNames.lib + Name("HTMLDivElement"), QualifiedName("org.scalajs.dom.HTMLDivElement")),
Expand Down Expand Up @@ -204,19 +204,18 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("HmacImportParams"), QualifiedName("org.scalajs.dom.HmacImportParams")),
CastConversion(stdNames.lib + Name("HmacKeyAlgorithm"), QualifiedName("org.scalajs.dom.HmacKeyAlgorithm")),
CastConversion(stdNames.lib + Name("HmacKeyGenParams"), QualifiedName("org.scalajs.dom.HmacKeyGenParams")),
CastConversion(stdNames.lib + Name("IDBCursor"), QualifiedName("org.scalajs.dom.IDBCursor")),
CastConversion(stdNames.lib + Name("IDBCursorWithValue"), QualifiedName("org.scalajs.dom.IDBCursorWithValue")),
CastConversion(stdNames.lib + Name("IDBCursor"), QualifiedName("org.scalajs.dom.IDBCursor"), TParam._1),
CastConversion(stdNames.lib + Name("IDBCursorWithValue"), QualifiedName("org.scalajs.dom.IDBCursorWithValue"), TParam._1),
CastConversion(stdNames.lib + Name("IDBDatabase"), QualifiedName("org.scalajs.dom.IDBDatabase")),
CastConversion(stdNames.lib + Name("IDBEnvironment"), QualifiedName("org.scalajs.dom.IDBEnvironment")),
CastConversion(stdNames.lib + Name("IDBFactory"), QualifiedName("org.scalajs.dom.IDBFactory")),
CastConversion(stdNames.lib + Name("IDBIndex"), QualifiedName("org.scalajs.dom.IDBIndex")),
CastConversion(stdNames.lib + Name("IDBKeyRange"), QualifiedName("org.scalajs.dom.IDBKeyRange")),
CastConversion(stdNames.lib + Name("IDBObjectStore"), QualifiedName("org.scalajs.dom.IDBObjectStore")),
CastConversion(stdNames.lib + Name("IDBOpenDBRequest"), QualifiedName("org.scalajs.dom.IDBOpenDBRequest")),
CastConversion(stdNames.lib + Name("IDBRequest"), QualifiedName("org.scalajs.dom.IDBRequest")),
CastConversion(stdNames.lib + Name("IDBOpenDBRequest"), QualifiedName("org.scalajs.dom.IDBOpenDBRequest"), TParam._1),
CastConversion(stdNames.lib + Name("IDBRequest"), QualifiedName("org.scalajs.dom.IDBRequest"), CastConversion.TParam.Ref(TypeRef.Any), TParam._1),
CastConversion(stdNames.lib + Name("IDBTransaction"), QualifiedName("org.scalajs.dom.IDBTransaction")),
CastConversion(stdNames.lib + Name("IDBVersionChangeEvent"), QualifiedName("org.scalajs.dom.IDBVersionChangeEvent")),
CastConversion(stdNames.lib + Name("Image"), QualifiedName("org.scalajs.dom.ext.Image")),
CastConversion(stdNames.lib + Name("ImageData"), QualifiedName("org.scalajs.dom.ImageData")),
CastConversion(stdNames.lib + Name("Int16Array"), QualifiedName("scala.scalajs.js.typedarray.Int16Array")),
CastConversion(stdNames.lib + Name("Int32Array"), QualifiedName("scala.scalajs.js.typedarray.Int32Array")),
Expand All @@ -227,8 +226,8 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("Intl.DateTimeFormatOptions"), QualifiedName("org.scalajs.dom.intl.DateTimeFormatOptions")),
CastConversion(stdNames.lib + Name("Intl.NumberFormat"), QualifiedName("org.scalajs.dom.intl.NumberFormat")),
CastConversion(stdNames.lib + Name("Intl.NumberFormatOptions"), QualifiedName("org.scalajs.dom.intl.NumberFormatOptions")),
CastConversion(stdNames.lib + Name("Iterable"), QualifiedName("scala.scalajs.js.Iterable"), _1),
CastConversion(stdNames.lib + Name("Iterator"), QualifiedName("scala.scalajs.js.Iterator"), _1),
CastConversion(stdNames.lib + Name("Iterable"), QualifiedName("scala.scalajs.js.Iterable"), TParam._1),
CastConversion(stdNames.lib + Name("Iterator"), QualifiedName("scala.scalajs.js.Iterator"), TParam._1),
CastConversion(stdNames.lib + Name("JsonWebKey"), QualifiedName("org.scalajs.dom.JsonWebKey")),
CastConversion(stdNames.lib + Name("KeyAlgorithm"), QualifiedName("org.scalajs.dom.KeyAlgorithm")),
CastConversion(stdNames.lib + Name("KeyFormat"), QualifiedName("org.scalajs.dom.KeyFormat")),
Expand Down Expand Up @@ -273,8 +272,8 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("Node"), QualifiedName("org.scalajs.dom.Node")),
CastConversion(stdNames.lib + Name("NodeFilter"), QualifiedName("org.scalajs.dom.NodeFilter")),
CastConversion(stdNames.lib + Name("NodeIterator"), QualifiedName("org.scalajs.dom.NodeIterator")),
CastConversion(stdNames.lib + Name("NodeList"), QualifiedName("org.scalajs.dom.NodeList")),
CastConversion(stdNames.lib + Name("NodeListOf"), QualifiedName("org.scalajs.dom.NodeListOf"), _1.among(Set.empty, QualifiedName("org.scalajs.dom.Node"))),
CastConversion(stdNames.lib + Name("NodeList"), QualifiedName("org.scalajs.dom.NodeList"), TParam.Ref(TypeRef(QualifiedName("org.scalajs.dom.Node")))),
CastConversion(stdNames.lib + Name("NodeListOf"), QualifiedName("org.scalajs.dom.NodeList"), TParam._1.among(Set.empty, QualifiedName("org.scalajs.dom.Node"))),
CastConversion(stdNames.lib + Name("NonDocumentTypeChildNode"), QualifiedName("org.scalajs.dom.NonDocumentTypeChildNode")),
CastConversion(stdNames.lib + Name("Notification"), QualifiedName("org.scalajs.dom.Notification")),
CastConversion(stdNames.lib + Name("NotificationOptions"), QualifiedName("org.scalajs.dom.NotificationOptions")),
Expand All @@ -301,7 +300,7 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("PositionOptions"), QualifiedName("org.scalajs.dom.PositionOptions")),
CastConversion(stdNames.lib + Name("ProcessingInstruction"), QualifiedName("org.scalajs.dom.ProcessingInstruction")),
CastConversion(stdNames.lib + Name("ProgressEvent"), QualifiedName("org.scalajs.dom.ProgressEvent")),
CastConversion(stdNames.lib + Name("Promise"), QualifiedName("scala.scalajs.js.Promise"), _1),
CastConversion(stdNames.lib + Name("Promise"), QualifiedName("scala.scalajs.js.Promise"), TParam._1),
CastConversion(stdNames.lib + Name("PropertyDescriptor"), QualifiedName("scala.scalajs.js.PropertyDescriptor")),
CastConversion(stdNames.lib + Name("PushEncryptionKeyName"), QualifiedName("org.scalajs.dom.PushEncryptionKeyName")),
CastConversion(stdNames.lib + Name("PushManager"), QualifiedName("org.scalajs.dom.PushManager")),
Expand Down Expand Up @@ -337,11 +336,10 @@ class ScalaJsDomNames(stdNames: QualifiedName.StdNames) {
CastConversion(stdNames.lib + Name("RTCStatsType"), QualifiedName("org.scalajs.dom.RTCStatsType")),
CastConversion(stdNames.lib + Name("Range"), QualifiedName("org.scalajs.dom.Range")),
CastConversion(stdNames.lib + Name("RangeError"), QualifiedName("scala.scalajs.js.RangeError")),
CastConversion(stdNames.lib + Name("ReadableStream"), QualifiedName("org.scalajs.dom.ReadableStream"), _1),
CastConversion(stdNames.lib + Name("ReadableStreamReader"), QualifiedName("org.scalajs.dom.ReadableStreamReader"), _1),
CastConversion(stdNames.lib + Name("ReadableStream"), QualifiedName("org.scalajs.dom.ReadableStream"), TParam._1),
CastConversion(stdNames.lib + Name("ReadableStreamReader"), QualifiedName("org.scalajs.dom.ReadableStreamReader"), TParam._1),
CastConversion(stdNames.lib + Name("ReferenceError"), QualifiedName("scala.scalajs.js.ReferenceError")),
CastConversion(stdNames.lib + Name("ReferrerPolicy"), QualifiedName("org.scalajs.dom.ReferrerPolicy")),
CastConversion(stdNames.lib + Name("Reflect"), QualifiedName("scala.scalajs.reflect.Reflect")),
CastConversion(stdNames.lib + Name("RegExp"), QualifiedName("scala.scalajs.js.RegExp")),
CastConversion(stdNames.lib + Name("Request"), QualifiedName("org.scalajs.dom.Request")),
CastConversion(stdNames.lib + Name("RequestCache"), QualifiedName("org.scalajs.dom.RequestCache")),
Expand Down

0 comments on commit b3efa41

Please sign in to comment.