Chore: linting

This commit is contained in:
Pieter Vander Vennet 2024-04-13 02:40:21 +02:00
parent 4625ad9a5c
commit 097141f944
307 changed files with 5346 additions and 2147 deletions

View file

@ -65,31 +65,37 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
const newFilters: FilterConfigJson[] = []
const filters = <(FilterConfigJson | string)[]>json.filter
for (let i = 0; i < filters.length; i++){
for (let i = 0; i < filters.length; i++) {
const filter = filters[i]
if (typeof filter !== "string") {
newFilters.push(filter)
continue
}
const matchingTr =<TagRenderingConfigJson> json.tagRenderings.find(tr => !!tr && tr["id"] === filter)
if(matchingTr){
if(!(matchingTr.mappings?.length >= 1)){
context.enters("filter",i ).err("Found a matching tagRendering to base a filter on, but this tagRendering does not contain any mappings")
const matchingTr = <TagRenderingConfigJson>(
json.tagRenderings.find((tr) => !!tr && tr["id"] === filter)
)
if (matchingTr) {
if (!(matchingTr.mappings?.length >= 1)) {
context
.enters("filter", i)
.err(
"Found a matching tagRendering to base a filter on, but this tagRendering does not contain any mappings"
)
}
const options = matchingTr.mappings.map(mapping => ({
const options = matchingTr.mappings.map((mapping) => ({
question: mapping.then,
osmTags: mapping.if
osmTags: mapping.if,
}))
options.unshift({
question: {
en:"All types"
en: "All types",
},
osmTags: undefined
osmTags: undefined,
})
newFilters.push({
id: filter,
options
options,
})
continue
}
@ -521,9 +527,9 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
json = { ...json }
json.tagRenderings = [...json.tagRenderings]
const allSpecials: Exclude<RenderingSpecification, string>[] = <any>(
ValidationUtils.getAllSpecialVisualisations(<QuestionableTagRenderingConfigJson[]> json.tagRenderings).filter(
(spec) => typeof spec !== "string"
)
ValidationUtils.getAllSpecialVisualisations(
<QuestionableTagRenderingConfigJson[]>json.tagRenderings
).filter((spec) => typeof spec !== "string")
)
const questionSpecials = allSpecials.filter((sp) => sp.func.funcName === "questions")

View file

@ -289,7 +289,10 @@ class AddContextToTranslationsInLayout extends DesugaringStep<LayoutConfigJson>
convert(json: LayoutConfigJson): LayoutConfigJson {
const conversion = new AddContextToTranslations<LayoutConfigJson>("themes:")
// The context is used to generate the 'context' in the translation .It _must_ be `json.id` to correctly link into weblate
return conversion.convert(json, ConversionContext.construct([json.id],["AddContextToTranslation"]))
return conversion.convert(
json,
ConversionContext.construct([json.id], ["AddContextToTranslation"])
)
}
}
@ -602,19 +605,32 @@ class PostvalidateTheme extends DesugaringStep<LayoutConfigJson> {
}
for (const layer of json.layers) {
if(typeof layer === "string"){
if (typeof layer === "string") {
continue
}
const config = <LayerConfigJson> layer;
const config = <LayerConfigJson>layer
const sameAs = config.filter?.["sameAs"]
if(!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(", "))
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(", ")
)
}
}

View file

@ -278,10 +278,14 @@ export class ValidateTheme extends DesugaringStep<LayoutConfigJson> {
if (!isCategory && !ValidateTheme._availableLayers.has(backgroundId)) {
const options = Array.from(ValidateTheme._availableLayers)
const nearby = Utils.sortedByLevenshteinDistance(backgroundId, options, t => t)
const nearby = Utils.sortedByLevenshteinDistance(backgroundId, options, (t) => t)
context
.enter("defaultBackgroundId")
.err(`This layer ID is not known: ${backgroundId}. Perhaps you meant one of ${nearby.slice(0,5).join(", ")}`)
.err(
`This layer ID is not known: ${backgroundId}. Perhaps you meant one of ${nearby
.slice(0, 5)
.join(", ")}`
)
}
}
@ -1014,7 +1018,7 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
) {
continue
}
if(json.freeform.key.indexOf("wikidata")>=0){
if (json.freeform.key.indexOf("wikidata") >= 0) {
context
.enter("render")
.err(
@ -1273,7 +1277,14 @@ export class PrevalidateLayer extends DesugaringStep<LayerConfigJson> {
// It is tempting to add an index to this warning; however, due to labels the indices here might be different from the index in the tagRendering list
context
.enter("tagRenderings")
.err("Some tagrenderings have a duplicate id: " + duplicates.join(", ")+"\n"+JSON.stringify(json.tagRenderings.filter(tr=> duplicates.indexOf(tr["id"])>=0)))
.err(
"Some tagrenderings have a duplicate id: " +
duplicates.join(", ") +
"\n" +
JSON.stringify(
json.tagRenderings.filter((tr) => duplicates.indexOf(tr["id"]) >= 0)
)
)
}
}
@ -1865,11 +1876,14 @@ export class ValidateThemeEnsemble extends Conversion<
string,
{
tags: TagsFilter
foundInTheme: string[],
foundInTheme: string[]
isCounted: boolean
}
> {
const idToSource = new Map<string, { tags: TagsFilter; foundInTheme: string[], isCounted: boolean }>()
const idToSource = new Map<
string,
{ tags: TagsFilter; foundInTheme: string[]; isCounted: boolean }
>()
for (const theme of json) {
for (const layer of theme.layers) {

View file

@ -62,8 +62,6 @@ export default class ValidationUtils {
}
for (const key in translation) {
const template = translation[key]
const parts = SpecialVisualizations.constructSpecification(template)
const specials = parts.filter((p) => typeof p !== "string")