From fffc959c0dd01c2fdcacc02661c77e646bce8bf7 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 17 Apr 2025 02:25:51 +0200 Subject: [PATCH] Chore: cleanup typings and linting errors --- scripts/serverLdScrape.ts | 20 ++------------- .../Osm/Actions/ReplaceGeometryAction.ts | 25 +++++++++---------- src/Logic/Osm/Changes.ts | 1 - src/UI/Popup/ImportButtons/ImportFlow.ts | 13 +++++----- .../TagRendering/TagRenderingQuestion.svelte | 1 - src/Utils.ts | 2 +- 6 files changed, 21 insertions(+), 41 deletions(-) diff --git a/scripts/serverLdScrape.ts b/scripts/serverLdScrape.ts index a75052cb63..c330d41e1f 100644 --- a/scripts/serverLdScrape.ts +++ b/scripts/serverLdScrape.ts @@ -21,24 +21,8 @@ class ServerLdScrape extends Script { /* { "User-Agent": "MapComplete/openstreetmap scraper; pietervdvn@posteo.net; https://source.mapcomplete.org/MapComplete", "accept": "application/html" - }, - { - Host: host, - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:122.0) Gecko/20100101 Firefox/122.0", - "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,* /*;q=0.8", TODO remove space in * /* - "Accept-Language": "en-US,en;q=0.5", - "Accept-Encoding": "gzip, deflate, br", - "Alt-Used": host, - DNT: 1, - "Sec-GPC": 1, - "Upgrade-Insecure-Requests": 1, - "Sec-Fetch-Dest": "document", - "Sec-Fetch-Mode": "navigate", - "Sec-Fetch-Site": "cross-site", - "Sec-Fetch-User":"?1", - "TE": "trailers", - Connection: "keep-alive" - }*/ + },*/ + ] for (let i = 0; i < headers.length; i++) { try { diff --git a/src/Logic/Osm/Actions/ReplaceGeometryAction.ts b/src/Logic/Osm/Actions/ReplaceGeometryAction.ts index 07904c955f..69eac7e582 100644 --- a/src/Logic/Osm/Actions/ReplaceGeometryAction.ts +++ b/src/Logic/Osm/Actions/ReplaceGeometryAction.ts @@ -11,15 +11,14 @@ import ChangeTagAction from "./ChangeTagAction" import { And } from "../../Tags/And" import { Utils } from "../../../Utils" import { OsmConnection } from "../OsmConnection" -import { Feature } from "@turf/turf" -import { Geometry, LineString, Point } from "geojson" +import { Feature, Geometry, LineString, Point } from "geojson" import FullNodeDatabaseSource from "../../FeatureSource/TiledFeatureSource/FullNodeDatabaseSource" export default class ReplaceGeometryAction extends OsmChangeAction implements PreviewableAction { /** * The target feature - mostly used for the metadata */ - private readonly feature: any + private readonly feature: Feature private readonly state: { osmConnection: OsmConnection fullNodeDatabase?: FullNodeDatabaseSource @@ -48,7 +47,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr osmConnection: OsmConnection fullNodeDatabase?: FullNodeDatabaseSource }, - feature: any, + feature: Feature, wayToReplaceId: string, options: { theme: string @@ -65,13 +64,13 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr const geom = this.feature.geometry let coordinates: [number, number][] if (geom.type === "LineString") { - coordinates = geom.coordinates + coordinates = <[number, number][]>geom.coordinates } else if (geom.type === "Polygon") { - coordinates = geom.coordinates[0] + coordinates = <[number, number][]>geom.coordinates[0] } this.targetCoordinates = coordinates - this.identicalTo = coordinates.map((_) => undefined) + this.identicalTo = coordinates.map(() => undefined) for (let i = 0; i < coordinates.length; i++) { if (this.identicalTo[i] !== undefined) { @@ -204,7 +203,6 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr if (nodeDb === undefined) { throw "PANIC: replaceGeometryAction needs the FullNodeDatabase, which is undefined. This should be initialized by having the 'type_node'-layer enabled in your theme. (NB: the replacebutton has type_node as dependency)" } - const self = this let parsed: OsmObject[] { // Gather the needed OsmObjects @@ -214,6 +212,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr if (idN < 0 || type !== "way") { throw "Invalid ID to conflate: " + this.wayToReplaceId } + const url = `${ this.state.osmConnection?._oauth_config?.url ?? "https://api.openstreetmap.org" }/api/0.6/${this.wayToReplaceId}/full` @@ -270,7 +269,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr const partOfSomeWay = parentWayIds.length > 0 const hasTags = Object.keys(node.tags).length > 1 - const nodeDistances = this.targetCoordinates.map((_) => undefined) + const nodeDistances = this.targetCoordinates.map(() => undefined) for (let i = 0; i < this.targetCoordinates.length; i++) { if (this.identicalTo[i] !== undefined) { continue @@ -295,7 +294,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr }) } - const closestIds = this.targetCoordinates.map((_) => undefined) + const closestIds = this.targetCoordinates.map(() => undefined) const unusedIds = new Map< number, { @@ -330,7 +329,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr // We found a candidate... Search the corresponding target id: let targetId: number = undefined let lowestDistance = Number.MAX_VALUE - let nodeDistances = distances.get(candidate) + const nodeDistances = distances.get(candidate) for (let i = 0; i < nodeDistances.length; i++) { const d = nodeDistances[i] if (d !== undefined && d < lowestDistance) { @@ -400,7 +399,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr properties: {}, geometry: { type: "LineString", - coordinates: self.targetCoordinates, + coordinates: this.targetCoordinates }, } const projected = GeoOperations.nearestPoint(way, [node.lon, node.lat]) @@ -528,7 +527,7 @@ export default class ReplaceGeometryAction extends OsmChangeAction implements Pr // Some nodes might need to be deleted if (detachedNodes.size > 0) { - detachedNodes.forEach(({ hasTags, reason }, nodeId) => { + detachedNodes.forEach(({ hasTags }, nodeId) => { const parentWays = nodeDb.GetParentWays(nodeId) const index = parentWays.data.map((w) => w.id).indexOf(osmWay.id) if (index < 0) { diff --git a/src/Logic/Osm/Changes.ts b/src/Logic/Osm/Changes.ts index 170755f0c8..34a498afc9 100644 --- a/src/Logic/Osm/Changes.ts +++ b/src/Logic/Osm/Changes.ts @@ -233,7 +233,6 @@ export class Changes { ...addSource(DeleteAction.metatags, "DeleteAction"), // TODO /* - ...DeleteAction.metatags, ...LinkImageAction.metatags, ...OsmChangeAction.metatags, ...RelationSplitHandler.metatags, diff --git a/src/UI/Popup/ImportButtons/ImportFlow.ts b/src/UI/Popup/ImportButtons/ImportFlow.ts index ce0fd11c4d..6762088e5c 100644 --- a/src/UI/Popup/ImportButtons/ImportFlow.ts +++ b/src/UI/Popup/ImportButtons/ImportFlow.ts @@ -9,7 +9,8 @@ import FilteredLayer from "../../../Models/FilteredLayer" import LayerConfig from "../../../Models/ThemeConfig/LayerConfig" import { LayerConfigJson } from "../../../Models/ThemeConfig/Json/LayerConfigJson" import conflation_json from "../../../../assets/layers/conflation/conflation.json" -import ThemeViewState from "../../../Models/ThemeViewState" +import { SpecialVisualizationState } from "../../SpecialVisualization" +import { OsmTags } from "../../../Models/OsmFeature" export interface ImportFlowArguments { readonly text: string @@ -65,7 +66,7 @@ ${Utils.special_visualizations_importRequirementDocs} * Given the tagsstore of the point which represents the challenge, creates a new store with tags that should be applied onto the newly created point, */ public static getTagsToApply( - originalFeatureTags: UIEventSource, + originalFeatureTags: UIEventSource, args: { tags: string } ): Store { if (originalFeatureTags === undefined) { @@ -109,9 +110,7 @@ ${Utils.special_visualizations_importRequirementDocs} * Others (e.g.: snapOnto-layers) are not to be handled here */ public static getLayerDependencies(argsRaw: string[], argSpec?): string[] { - const args: ImportFlowArguments = ( - Utils.ParseVisArgs(argSpec ?? ImportFlowUtils.generalArguments, argsRaw) - ) + const args = Utils.ParseVisArgs(argSpec ?? ImportFlowUtils.generalArguments, argsRaw) return args.targetLayer.split(" ") } @@ -139,14 +138,14 @@ ${Utils.special_visualizations_importRequirementDocs} * This class works together closely with ImportFlow.svelte */ export default abstract class ImportFlow { - public readonly state: ThemeViewState + public readonly state: SpecialVisualizationState public readonly args: ArgT public readonly targetLayer: FilteredLayer[] public readonly tagsToApply: Store protected readonly _originalFeatureTags: UIEventSource> constructor( - state: ThemeViewState, + state: SpecialVisualizationState, args: ArgT, tagsToApply: Store, originalTags: UIEventSource> diff --git a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte index 1ee9cd24ae..f565f9fdda 100644 --- a/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte +++ b/src/UI/Popup/TagRendering/TagRenderingQuestion.svelte @@ -137,7 +137,6 @@ } unseenFreeformValues.splice(index, 1) } - // TODO this has _to much_ values freeformInput.set(unseenFreeformValues.join(";")) if (checkedMappings.length + 1 < mappings.length) { checkedMappings.push(unseenFreeformValues.length > 0) diff --git a/src/Utils.ts b/src/Utils.ts index 23f31da24c..b705d51cd6 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -81,7 +81,7 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be /** * Parses the arguments for special visualisations */ - public static ParseVisArgs>( + public static ParseVisArgs>( specs: { name: string; defaultValue?: string }[], args: string[] ): T {