From 9885099aff545979dfde9e6e414664fad4439d42 Mon Sep 17 00:00:00 2001 From: Robin van der Linde Date: Thu, 27 Jul 2023 14:41:55 +0200 Subject: [PATCH] Fix some linting errors --- src/Utils.ts | 18 +++++++++--------- src/Utils/svgToPdf.ts | 38 +++++++++++++++++++------------------- src/all_themes_index.ts | 1 - 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/Utils.ts b/src/Utils.ts index 43da61605..be47cc1bb 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -233,7 +233,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } public static TimesT(count: number, f: (i: number) => T): T[] { - let res: T[] = [] + const res: T[] = [] for (let i = 0; i < count; i++) { res.push(f(i)) } @@ -827,7 +827,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } static getOrSetDefault(dict: Map, k: K, v: () => V) { - let found = dict.get(k) + const found = dict.get(k) if (found !== undefined) { return found } @@ -848,7 +848,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be if (i >= 124) { code += 1 // Character 127 is our 'escape' character | } - let replacement = "|" + String.fromCharCode(code) + const replacement = "|" + String.fromCharCode(code) stringified = stringified.replace(new RegExp(`\"${knownKey}\":`, "g"), replacement) } @@ -1125,7 +1125,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be seconds = seconds % 60 let hours = Math.floor(minutes / 60) minutes = minutes % 60 - let days = Math.floor(hours / 24) + const days = Math.floor(hours / 24) hours = hours % 24 if (days > 0) { return days + "days" + " " + hours + "h" @@ -1272,7 +1272,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be for (const k in d) { const vs = d[k] - for (let v of vs) { + for (const v of vs) { const list = newD[v] if (list === undefined) { newD[v] = [k] // Left: indexing; right: list with one element @@ -1294,7 +1294,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } function componentToHex(n) { - let hex = n.toString(16) + const hex = n.toString(16) return hex.length == 1 ? "0" + hex : hex } @@ -1413,8 +1413,8 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be return false } for (let i = 0; i < a.length; i++) { - let ai = a[i] - let bi = b[i] + const ai = a[i] + const bi = b[i] if (ai == bi) { continue } @@ -1508,7 +1508,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be if (matchWithFuncName) { ;[_, functionName, path, line, column] = matchWithFuncName } else { - let regexNoFuncName: RegExp = new RegExp("at ([a-zA-Z0-9/.]+):([0-9]+):([0-9]+)") + const regexNoFuncName: RegExp = new RegExp("at ([a-zA-Z0-9/.]+):([0-9]+):([0-9]+)") ;[_, path, line, column] = stackItem.match(regexNoFuncName) } diff --git a/src/Utils/svgToPdf.ts b/src/Utils/svgToPdf.ts index 991af6c2a..4bbc9e594 100644 --- a/src/Utils/svgToPdf.ts +++ b/src/Utils/svgToPdf.ts @@ -209,7 +209,7 @@ class SvgToPdfInternals { if (element.childElementCount == 0) { this.drawTspan(element) } else { - for (let child of Array.from(element.children)) { + for (const child of Array.from(element.children)) { this.handleElement(child) } } @@ -224,7 +224,7 @@ class SvgToPdfInternals { } if (element.tagName === "g" || element.tagName === "text") { - for (let child of Array.from(element.children)) { + for (const child of Array.from(element.children)) { this.handleElement(child) } } @@ -256,7 +256,7 @@ class SvgToPdfInternals { const css = SvgToPdfInternals.css(element) this.doc.saveGraphicsState() if (css["fill-opacity"] !== "0" && css["fill"] !== "none") { - let color = css["fill"] ?? "black" + const color = css["fill"] ?? "black" let opacity = 1 if (css["fill-opacity"]) { opacity = Number(css["fill-opacity"]) @@ -314,13 +314,13 @@ class SvgToPdfInternals { console.log("Creating image with key", key, "searching rect in", x, y) const rectangle: SVGRectElement = this.page.findSmallestRectContaining(x, y, false) console.log("Got rect", rectangle) - let w = SvgToPdfInternals.attrNumber(rectangle, "width") - let h = SvgToPdfInternals.attrNumber(rectangle, "height") + const w = SvgToPdfInternals.attrNumber(rectangle, "width") + const h = SvgToPdfInternals.attrNumber(rectangle, "height") x = SvgToPdfInternals.attrNumber(rectangle, "x") y = SvgToPdfInternals.attrNumber(rectangle, "y") // Actually, dots per mm, not dots per inch ;) - let dpi = 60 + const dpi = 60 const img = this.page.options.createImage(key, dpi * w + "px", dpi * h + "px") const canvas = document.createElement("canvas") @@ -363,7 +363,7 @@ class SvgToPdfInternals { fontFamily = "Ubuntu" } - let fontWeight = css["font-weight"] ?? "normal" + const fontWeight = css["font-weight"] ?? "normal" this.doc.setFont(fontFamily, fontWeight) const fontColor = css["fill"] @@ -372,13 +372,13 @@ class SvgToPdfInternals { } else { this.doc.setTextColor("black") } - let fontsize = parseFloat(css["font-size"]) + const fontsize = parseFloat(css["font-size"]) this.doc.setFontSize(fontsize * 2.5) - let textTemplate = tspan.textContent.split(" ") + const textTemplate = tspan.textContent.split(" ") let result: string = "" let addSpace = false - for (let text of textTemplate) { + for (const text of textTemplate) { if (text === "\\n") { result += "\n" addSpace = false @@ -446,7 +446,7 @@ class SvgToPdfInternals { const svgWidth = SvgToPdfInternals.attrNumber(svgRoot, "width") const svgHeight = SvgToPdfInternals.attrNumber(svgRoot, "height") - let img = this.page.images[base64src] + const img = this.page.images[base64src] // This is an svg image, we use the canvas to convert it to a png const canvas = document.createElement("canvas") const ctx = canvas.getContext("2d") @@ -607,7 +607,7 @@ class SvgToPdfPage { const parts = tc.split(" ").filter((p) => p.startsWith("$") && p.indexOf("(") < 0) for (let part of parts) { part = part.substring(1) // Drop the $ - let path = part.split(".") + const path = part.split(".") const importPath = this.importedTranslations[path[0]] if (importPath) { translations.add(importPath + "." + path.slice(1).join(".")) @@ -636,7 +636,7 @@ class SvgToPdfPage { if (element.tagName === "tspan" && element.childElementCount == 0) { const specialValues = element.textContent.split(" ").filter((t) => t.startsWith("$")) - for (let specialValue of specialValues) { + for (const specialValue of specialValues) { const importMatch = element.textContent.match( /\$import ([a-zA-Z-_0-9.? ]+) as ([a-zA-Z0-9]+)/ ) @@ -665,7 +665,7 @@ class SvgToPdfPage { element.tagName === "tspan" || element.tagName === "defs" ) { - for (let child of Array.from(element.children)) { + for (const child of Array.from(element.children)) { await this.prepareElement(child, mapTextSpecs, inDefs || element.tagName === "defs") } } @@ -694,7 +694,7 @@ class SvgToPdfPage { } this._isPrepared = true const mapSpecs: SVGTSpanElement[] = [] - for (let child of Array.from(this._svgRoot.children)) { + for (const child of Array.from(this._svgRoot.children)) { await this.prepareElement(child, mapSpecs, child.tagName === "defs") } @@ -715,7 +715,7 @@ class SvgToPdfPage { const internal = new SvgToPdfInternals(advancedApi, this, (key) => self.extractTranslation(key, language) ) - for (let child of Array.from(this._svgRoot.children)) { + for (const child of Array.from(this._svgRoot.children)) { internal.handleElement(child) } } @@ -805,11 +805,11 @@ class SvgToPdfPage { private loadImage(element: Element | string): Promise { const xlink = typeof element === "string" ? element : element.getAttribute("xlink:href") - let img = document.createElement("img") + const img = document.createElement("img") if (xlink.startsWith("data:image/svg+xml;")) { const base64src = xlink - let svgXml = atob( + const svgXml = atob( base64src.substring(base64src.indexOf(";base64,") + ";base64,".length) ) const parser = new DOMParser() @@ -884,7 +884,7 @@ class SvgToPdfPage { throw "Invalid mapspec:" + spec } const params = SvgToPdfInternals.parseCss(match[1], ",") - let layout = AllKnownLayouts.allKnownLayouts.get(params["theme"]) + const layout = AllKnownLayouts.allKnownLayouts.get(params["theme"]) if (layout === undefined) { console.error("Could not show map with parameters", params) throw ( diff --git a/src/all_themes_index.ts b/src/all_themes_index.ts index 3be1783d5..d04c88c71 100644 --- a/src/all_themes_index.ts +++ b/src/all_themes_index.ts @@ -1,4 +1,3 @@ -import { Utils } from "./Utils" import AllThemesGui from "./UI/AllThemesGui" import { QueryParameters } from "./Logic/Web/QueryParameters"