From 92c4d5acea9cba7bce999a0b21968a6071910a10 Mon Sep 17 00:00:00 2001 From: ligi Date: Mon, 13 Mar 2023 10:55:03 +0100 Subject: [PATCH] Check for unused explorer icons --- .../kotlin/org/ethereum/lists/chains/Main.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt index 482a1bdc..5ca9d8b2 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -135,7 +135,7 @@ private fun doChecks(doRPCConnect: Boolean, doIconDownload: Boolean, verbose: Bo if (!allIconCIDs.contains(it.name)) unusedIconDownload.add(it.name) } if (unusedIconDownload.isNotEmpty()) { - throw UnreferencedIcon(unusedIconDownload.joinToString (" ") , iconsDownloadPath) + throw UnreferencedIcon(unusedIconDownload.joinToString(" "), iconsDownloadPath) } allFiles.filter { it.isDirectory }.forEach { _ -> error("should not contain a directory") @@ -269,13 +269,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } jsonObject["icon"]?.let { - if (it !is String) { - error("icon must be string") - } - if (!File(iconsPath, "$it.json").exists()) { - error("The Icon $it does not exist - was used in ${chainFile.name}") - } - allUsedIcons.add(it) + processIcon(it, chainFile) } val nameRegex = Regex("^[a-zA-Z0-9\\-\\.\\(\\) ]+$") @@ -330,8 +324,8 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { throw (ExplorerMustHaveName()) } - if (explorer["icon"] != null) { - allUsedIcons.add(explorer["icon"].toString()) + explorer["icon"]?.let { explorerIcon -> + processIcon(explorerIcon, chainFile) } val url = explorer["url"] @@ -477,6 +471,16 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } } +private fun processIcon(it: Any, chainFile: File): Boolean { + if (it !is String) { + error("icon must be string") + } + if (!File(iconsPath, "$it.json").exists()) { + error("The Icon $it does not exist - was used in ${chainFile.name}") + } + return allUsedIcons.add(it) +} + private fun String.checkString(which: String) { if (isBlank()) { throw StringCannotBeBlank(which)