Themes: add compile time check for 'sameAs'-filters that the referenced layer actually exists

This commit is contained in:
Pieter Vander Vennet 2024-04-05 12:02:10 +02:00
parent ea00c717de
commit e188b96561
6 changed files with 25 additions and 4 deletions

View file

@ -683,6 +683,10 @@
"en": "Who maintains this bicycle parking?",
"nl": "Wie beheert deze fietsenstalling?"
},
"render": {
"en": "This bicycle parking is maintained by {operator}",
"nl": "Deze fietsenstalling wordt beheerd door {operator}"
},
"freeform": {
"key": "operator"
}

View file

@ -57,7 +57,7 @@
"minzoom": 18,
"name": null,
"filter": {
"sameAs": "bank_with_atm"
"sameAs": "banks_with_atm"
},
"doCount": false
}

View file

@ -151,7 +151,7 @@
"override": {
"name": null,
"filter": {
"sameAs": "charging_station_ebike"
"sameAs": "charging_station_ebikes"
},
"minzoom": 18
}

View file

@ -53,7 +53,7 @@
"=name": null,
"doCount": false,
"=filter": {
"sameAs": "erotic-shop"
"sameAs": "erotic_shop"
}
}
},

View file

@ -83,7 +83,7 @@
"override": {
"name": null,
"filter": {
"sameAs": "charging_station_ebike"
"sameAs": "charging_station_ebikes"
},
"minzoom": 18,
"=presets": []

View file

@ -600,6 +600,23 @@ class PostvalidateTheme extends DesugaringStep<LayoutConfigJson> {
}
}
for (const layer of json.layers) {
if(typeof layer === "string"){
continue
}
const config = <LayerConfigJson> layer;
const sameAs = config.filter?.["sameAs"]
if(!sameAs){
continue
}
const matchingLayer = json.layers.find(l => l["id"] === sameAs)
if(!matchingLayer){
const closeLayers = Utils.sortedByLevenshteinDistance(sameAs, json.layers, l => l["id"]).map(l => l["id"])
context.enters("layers", config.id, "filter","sameAs").err("The layer "+config.id+" follows the filter state of layer "+sameAs+", but no layer with this name was found.\n\tDid you perhaps mean one of: "+closeLayers.slice(0, 3).join(", "))
}
}
return json
}
}