diff --git a/Logic/Tags/And.ts b/Logic/Tags/And.ts index 04c79a83c..507fe877b 100644 --- a/Logic/Tags/And.ts +++ b/Logic/Tags/And.ts @@ -244,8 +244,8 @@ export class And extends TagsFilter { } } - for (let i = 0; i < optimized.length; i++){ - const opt = optimized[i]; + for (let i = 0; i < optimized.length; i++) { + const opt = optimized[i] if (opt instanceof Tag) { const k = opt.key const v = properties[k] @@ -266,23 +266,24 @@ export class And extends TagsFilter { if (v === undefined) { continue } - if(opt.invert){ + if (opt.invert) { // We should _not_ match this value // If 'v' is given, we already know what value it should be // If 'v' is the not-expected value, we have a conflict and return false // Otherwise, we can safely drop this value - const doesMatch = (typeof opt.value === "string" && v === opt.value) || - (v.match( opt.value) !== null) + const doesMatch = + (typeof opt.value === "string" && v === opt.value) || + v.match(opt.value) !== null - if(doesMatch){ + if (doesMatch) { // We have a conflict as 'opt' is inverted return false - }else{ + } else { optimized.splice(i, 1) i-- } - }else if (v !== opt.value) { + } else if (v !== opt.value) { // detected an internal conflict return false } diff --git a/Models/ThemeConfig/Conversion/PrepareLayer.ts b/Models/ThemeConfig/Conversion/PrepareLayer.ts index 75acb6c6e..0535e61c4 100644 --- a/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -1,16 +1,26 @@ -import {Concat, Conversion, DesugaringContext, DesugaringStep, Each, FirstOf, Fuse, On, SetDefault,} from "./Conversion" -import {LayerConfigJson} from "../Json/LayerConfigJson" -import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson" -import {Utils} from "../../../Utils" +import { + Concat, + Conversion, + DesugaringContext, + DesugaringStep, + Each, + FirstOf, + Fuse, + On, + SetDefault, +} from "./Conversion" +import { LayerConfigJson } from "../Json/LayerConfigJson" +import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson" +import { Utils } from "../../../Utils" import RewritableConfigJson from "../Json/RewritableConfigJson" import SpecialVisualizations from "../../../UI/SpecialVisualizations" import Translations from "../../../UI/i18n/Translations" -import {Translation} from "../../../UI/i18n/Translation" +import { Translation } from "../../../UI/i18n/Translation" import tagrenderingconfigmeta from "../../../assets/tagrenderingconfigmeta.json" -import {AddContextToTranslations} from "./AddContextToTranslations" +import { AddContextToTranslations } from "./AddContextToTranslations" import FilterConfigJson from "../Json/FilterConfigJson" import predifined_filters from "../../../assets/layers/filters/filters.json" -import {TagConfigJson} from "../Json/TagConfigJson" +import { TagConfigJson } from "../Json/TagConfigJson" import PointRenderingConfigJson from "../Json/PointRenderingConfigJson" import LineRenderingConfigJson from "../Json/LineRenderingConfigJson" @@ -40,11 +50,11 @@ class ExpandFilter extends DesugaringStep { context: string ): { result: LayerConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } { if (json.filter === undefined || json.filter === null) { - return {result: json} // Nothing to change here + return { result: json } // Nothing to change here } if (json.filter["sameAs"] !== undefined) { - return {result: json} // Nothing to change here + return { result: json } // Nothing to change here } const newFilters: FilterConfigJson[] = [] @@ -60,9 +70,9 @@ class ExpandFilter extends DesugaringStep { if (split.length > 2) { errors.push( context + - ": invalid filter name: " + - filter + - ", expected `layername.filterid`" + ": invalid filter name: " + + filter + + ", expected `layername.filterid`" ) } const layer = this._state.sharedLayers.get(split[0]) @@ -161,7 +171,6 @@ class ExpandTagRendering extends Conversion< } private lookup(name: string): TagRenderingConfigJson[] | undefined { - const direct = this.directLookup(name) if (direct === undefined) { @@ -198,7 +207,7 @@ class ExpandTagRendering extends Conversion< if (state.tagRenderings.has(name)) { return [state.tagRenderings.get(name)] } - if(this._tagRenderingsByLabel.has(name)){ + if (this._tagRenderingsByLabel.has(name)) { return this._tagRenderingsByLabel.get(name) } @@ -239,7 +248,7 @@ class ExpandTagRendering extends Conversion< if (found.condition === undefined) { found.condition = layer.source.osmTags } else { - found.condition = {and: [found.condition, layer.source.osmTags]} + found.condition = { and: [found.condition, layer.source.osmTags] } } } @@ -276,18 +285,18 @@ class ExpandTagRendering extends Conversion< warnings.push( `${ctx}: A literal rendering was detected: ${tr} Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` + - Array.from(state.sharedLayers.keys()).join(", ") + Array.from(state.sharedLayers.keys()).join(", ") ) } if (this._options?.noHardcodedStrings && this._state.sharedLayers.size > 0) { errors.push( ctx + - "Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " + - tr + - " \n Did you perhaps forget to add the layer as prefix, such as `icons." + - tr + - "`? " + "Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " + + tr + + " \n Did you perhaps forget to add the layer as prefix, such as `icons." + + tr + + "`? " ) } @@ -318,11 +327,11 @@ class ExpandTagRendering extends Conversion< } errors.push( "At " + - ctx + - ": an object calling a builtin can only have keys `builtin` or `override`, but a key with name `" + - key + - "` was found. This won't be picked up! The full object is: " + - JSON.stringify(tr) + ctx + + ": an object calling a builtin can only have keys `builtin` or `override`, but a key with name `" + + key + + "` was found. This won't be picked up! The full object is: " + + JSON.stringify(tr) ) } @@ -346,22 +355,22 @@ class ExpandTagRendering extends Conversion< if (state.sharedLayers.size === 0) { warnings.push( ctx + - ": BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " + - name + - ": layer " + - layerName + - " not found. Maybe you meant on of " + - candidates.slice(0, 3).join(", ") + ": BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " + + name + + ": layer " + + layerName + + " not found. Maybe you meant on of " + + candidates.slice(0, 3).join(", ") ) } else { errors.push( ctx + - ": While reusing tagrendering: " + - name + - ": layer " + - layerName + - " not found. Maybe you meant on of " + - candidates.slice(0, 3).join(", ") + ": While reusing tagrendering: " + + name + + ": layer " + + layerName + + " not found. Maybe you meant on of " + + candidates.slice(0, 3).join(", ") ) } continue @@ -373,11 +382,11 @@ class ExpandTagRendering extends Conversion< candidates = Utils.sortedByLevenshteinDistance(name, candidates, (i) => i) errors.push( ctx + - ": The tagRendering with identifier " + - name + - " was not found.\n\tDid you mean one of " + - candidates.join(", ") + - "?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first" + ": The tagRendering with identifier " + + name + + " was not found.\n\tDid you mean one of " + + candidates.join(", ") + + "?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first" ) continue } @@ -463,7 +472,7 @@ export class ExpandRewrite extends Conversion, T[ } if (typeof obj === "object") { - obj = {...obj} + obj = { ...obj } const isTr = targetIsTranslation && Translations.isProbablyATranslation(obj) @@ -526,12 +535,12 @@ export class ExpandRewrite extends Conversion, T[ context: string ): { result: T[]; errors?: string[]; warnings?: string[]; information?: string[] } { if (json === null || json === undefined) { - return {result: []} + return { result: [] } } if (json["rewrite"] === undefined) { // not a rewrite - return {result: [json]} + return { result: [json] } } const rewrite = >json @@ -571,7 +580,7 @@ export class ExpandRewrite extends Conversion, T[ ts.push(t) } - return {result: ts} + return { result: ts } } } @@ -855,7 +864,7 @@ class ExpandIconBadges extends DesugaringStepjson).iconBadges @@ -866,7 +875,7 @@ class ExpandIconBadges extends DesugaringStep { new On( "titleIcons", (layer) => - new Concat(new ExpandTagRendering(state, layer, {noHardcodedStrings: true})) + new Concat(new ExpandTagRendering(state, layer, { noHardcodedStrings: true })) ), new ExpandFilter(state) ) diff --git a/Models/ThemeConfig/SourceConfig.ts b/Models/ThemeConfig/SourceConfig.ts index 7ad564764..7d285cdd7 100644 --- a/Models/ThemeConfig/SourceConfig.ts +++ b/Models/ThemeConfig/SourceConfig.ts @@ -58,8 +58,9 @@ export default class SourceConfig { "Error at " + context + ": the specified tags are conflicting with each other: they will never match anything at all.\n" + - "\tThe offending tags are: "+params.osmTags.asHumanString(false, false, {})+ - "\tThey optmize into 'false' " + "\tThe offending tags are: " + + params.osmTags.asHumanString(false, false, {}) + + "\tThey optmize into 'false' " ) } if (optimized === true) { diff --git a/test/Logic/Tags/OptimizeTags.spec.ts b/test/Logic/Tags/OptimizeTags.spec.ts index 06110eb54..ed90d8d01 100644 --- a/test/Logic/Tags/OptimizeTags.spec.ts +++ b/test/Logic/Tags/OptimizeTags.spec.ts @@ -1,10 +1,10 @@ -import {TagsFilter} from "../../../Logic/Tags/TagsFilter" -import {And} from "../../../Logic/Tags/And" -import {Tag} from "../../../Logic/Tags/Tag" -import {TagUtils} from "../../../Logic/Tags/TagUtils" -import {Or} from "../../../Logic/Tags/Or" -import {RegexTag} from "../../../Logic/Tags/RegexTag" -import {describe, expect, it} from "vitest" +import { TagsFilter } from "../../../Logic/Tags/TagsFilter" +import { And } from "../../../Logic/Tags/And" +import { Tag } from "../../../Logic/Tags/Tag" +import { TagUtils } from "../../../Logic/Tags/TagUtils" +import { Or } from "../../../Logic/Tags/Or" +import { RegexTag } from "../../../Logic/Tags/RegexTag" +import { describe, expect, it } from "vitest" describe("Tag optimalization", () => { describe("And", () => { @@ -76,7 +76,6 @@ describe("Tag optimalization", () => { const opt = t.optimize() expect(typeof opt !== "boolean").true expect(TagUtils.toString(opt)).toBe("shop=sports") - }) it("should optimize nested ORs", () => { @@ -271,7 +270,7 @@ describe("Tag optimalization", () => { or: [ "club=climbing", { - and: ["sport=climbing", {or: ["club~*", "office~*"]}], + and: ["sport=climbing", { or: ["club~*", "office~*"] }], }, { and: [ diff --git a/vitest.config.ts b/vitest.config.ts index 0d00fdf48..00a4ee2da 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -6,6 +6,6 @@ export default defineConfig({ test: { globals: true, setupFiles: ["./test/testhooks.ts"], - include: ["./test/*.spec.ts","./test/**/*.spec.ts", "./*.doctest.ts", "./**/*.doctest.ts"], + include: ["./test/*.spec.ts", "./test/**/*.spec.ts", "./*.doctest.ts", "./**/*.doctest.ts"], }, })