forked from MapComplete/MapComplete
		
	Chore: formatting
This commit is contained in:
		
							parent
							
								
									35eff07c80
								
							
						
					
					
						commit
						c08fe03ed0
					
				
					 422 changed files with 31594 additions and 43019 deletions
				
			
		| 
						 | 
				
			
			@ -39,7 +39,12 @@ export abstract class Conversion<TIn, TOut> {
 | 
			
		|||
            ConversionContext.print(msg)
 | 
			
		||||
        }
 | 
			
		||||
        if (context.hasErrors()) {
 | 
			
		||||
            throw new Error(["Detected one or more errors, stopping now:", context.getAll("error").map(e => e.context.path.join(".")+": "+e.message)].join("\n\t"))
 | 
			
		||||
            throw new Error(
 | 
			
		||||
                [
 | 
			
		||||
                    "Detected one or more errors, stopping now:",
 | 
			
		||||
                    context.getAll("error").map((e) => e.context.path.join(".") + ": " + e.message),
 | 
			
		||||
                ].join("\n\t")
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
        return fixed
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -157,10 +157,14 @@ export class ConversionContext {
 | 
			
		|||
     * @constructor
 | 
			
		||||
     */
 | 
			
		||||
    MergeObjectsForOverride<T, S>(source: Readonly<S>, target: T): T & S {
 | 
			
		||||
        try{
 | 
			
		||||
            return Utils.Merge(source,target)
 | 
			
		||||
        }catch (e) {
 | 
			
		||||
            this.err("Could not apply an override: due to "+e+"\n\tHINT: did you just pull changes from the repository or switch branches? Try 'npm run reset:layeroverview'")
 | 
			
		||||
        try {
 | 
			
		||||
            return Utils.Merge(source, target)
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            this.err(
 | 
			
		||||
                "Could not apply an override: due to " +
 | 
			
		||||
                    e +
 | 
			
		||||
                    "\n\tHINT: did you just pull changes from the repository or switch branches? Try 'npm run reset:layeroverview'"
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ export class UpdateLegacyLayer extends DesugaringStep<
 | 
			
		|||
            delete config["overpassTags"]
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(config.allowMove?.["enableImproveAccuraccy"]){
 | 
			
		||||
        if (config.allowMove?.["enableImproveAccuraccy"]) {
 | 
			
		||||
            // Fix common misspelling: 'accuracy' is often typo'ed as 'accuraCCy'
 | 
			
		||||
            config.allowMove["enableImproveAccuracy"] = config.allowMove["enableImproveAccuraccy"]
 | 
			
		||||
            delete config.allowMove["enableImproveAccuraccy"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -161,9 +161,8 @@ class ExpandTagRendering extends Conversion<
 | 
			
		|||
    private readonly _options: {
 | 
			
		||||
        /* If true, will copy the 'osmSource'-tags into the condition */
 | 
			
		||||
        applyCondition?: true | boolean
 | 
			
		||||
        noHardcodedStrings?: false | boolean,
 | 
			
		||||
        noHardcodedStrings?: false | boolean
 | 
			
		||||
        addToContext?: false | boolean
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    constructor(
 | 
			
		||||
| 
						 | 
				
			
			@ -171,7 +170,7 @@ class ExpandTagRendering extends Conversion<
 | 
			
		|||
        self: LayerConfigJson,
 | 
			
		||||
        options?: {
 | 
			
		||||
            applyCondition?: true | boolean
 | 
			
		||||
            noHardcodedStrings?: false | boolean,
 | 
			
		||||
            noHardcodedStrings?: false | boolean
 | 
			
		||||
            // If set, a question will be added to the 'sharedTagRenderings'. Should only be used for 'questions.json'
 | 
			
		||||
            addToContext?: false | boolean
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -208,17 +207,16 @@ class ExpandTagRendering extends Conversion<
 | 
			
		|||
            if (typeof tr === "string" || tr["builtin"] !== undefined) {
 | 
			
		||||
                const stable = this.convert(tr, ctx.inOperation("recursive_resolve"))
 | 
			
		||||
                result.push(...stable)
 | 
			
		||||
                if(this._options?.addToContext){
 | 
			
		||||
                if (this._options?.addToContext) {
 | 
			
		||||
                    for (const tr of stable) {
 | 
			
		||||
                        this._state.tagRenderings?.set(tr.id, tr)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                result.push(tr)
 | 
			
		||||
                if(this._options?.addToContext){
 | 
			
		||||
                    this._state.tagRenderings?.set(tr["id"], <QuestionableTagRenderingConfigJson> tr)
 | 
			
		||||
                if (this._options?.addToContext) {
 | 
			
		||||
                    this._state.tagRenderings?.set(tr["id"], <QuestionableTagRenderingConfigJson>tr)
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1274,14 +1272,23 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
export class PrepareLayer extends Fuse<LayerConfigJson> {
 | 
			
		||||
    constructor(state: DesugaringContext, options?: {addTagRenderingsToContext?: false | boolean}) {
 | 
			
		||||
    constructor(
 | 
			
		||||
        state: DesugaringContext,
 | 
			
		||||
        options?: { addTagRenderingsToContext?: false | boolean }
 | 
			
		||||
    ) {
 | 
			
		||||
        super(
 | 
			
		||||
            "Fully prepares and expands a layer for the LayerConfig.",
 | 
			
		||||
            new On("tagRenderings", new Each(new RewriteSpecial())),
 | 
			
		||||
            new On("tagRenderings", new Concat(new ExpandRewrite()).andThenF(Utils.Flatten)),
 | 
			
		||||
            new On("tagRenderings", (layer) => new Concat(new ExpandTagRendering(state, layer, {
 | 
			
		||||
                addToContext: options?.addTagRenderingsToContext ?? false
 | 
			
		||||
            }))),
 | 
			
		||||
            new On(
 | 
			
		||||
                "tagRenderings",
 | 
			
		||||
                (layer) =>
 | 
			
		||||
                    new Concat(
 | 
			
		||||
                        new ExpandTagRendering(state, layer, {
 | 
			
		||||
                            addToContext: options?.addTagRenderingsToContext ?? false,
 | 
			
		||||
                        })
 | 
			
		||||
                    )
 | 
			
		||||
            ),
 | 
			
		||||
            new On("tagRenderings", new Each(new DetectInline())),
 | 
			
		||||
            new AddQuestionBox(),
 | 
			
		||||
            new AddEditingElements(state),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -566,7 +566,11 @@ export class DetectMappingsShadowedByCondition extends DesugaringStep<TagRenderi
 | 
			
		|||
    private readonly _forceError: boolean
 | 
			
		||||
 | 
			
		||||
    constructor(forceError: boolean = false) {
 | 
			
		||||
        super("Checks that, if the tagrendering has a condition, that a mapping is not contradictory to it, i.e. that there are no dead mappings", [], "DetectMappingsShadowedByCondition")
 | 
			
		||||
        super(
 | 
			
		||||
            "Checks that, if the tagrendering has a condition, that a mapping is not contradictory to it, i.e. that there are no dead mappings",
 | 
			
		||||
            [],
 | 
			
		||||
            "DetectMappingsShadowedByCondition"
 | 
			
		||||
        )
 | 
			
		||||
        this._forceError = forceError
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -588,24 +592,28 @@ export class DetectMappingsShadowedByCondition extends DesugaringStep<TagRenderi
 | 
			
		|||
     * ctx.hasErrors() // => true
 | 
			
		||||
     */
 | 
			
		||||
    convert(json: TagRenderingConfigJson, context: ConversionContext): TagRenderingConfigJson {
 | 
			
		||||
        if(!json.condition && !json.metacondition){
 | 
			
		||||
        if (!json.condition && !json.metacondition) {
 | 
			
		||||
            return json
 | 
			
		||||
        }
 | 
			
		||||
        if(!json.mappings || json.mappings?.length ==0){
 | 
			
		||||
        if (!json.mappings || json.mappings?.length == 0) {
 | 
			
		||||
            return json
 | 
			
		||||
        }
 | 
			
		||||
        let conditionJson = json.condition ?? json.metacondition
 | 
			
		||||
        if(json.condition !== undefined && json.metacondition !== undefined){
 | 
			
		||||
            conditionJson = {and: [json.condition, json.metacondition]}
 | 
			
		||||
        if (json.condition !== undefined && json.metacondition !== undefined) {
 | 
			
		||||
            conditionJson = { and: [json.condition, json.metacondition] }
 | 
			
		||||
        }
 | 
			
		||||
        const condition = TagUtils.Tag(conditionJson, context.path.join("."))
 | 
			
		||||
 | 
			
		||||
        for (let i = 0; i < json.mappings.length; i++){
 | 
			
		||||
        for (let i = 0; i < json.mappings.length; i++) {
 | 
			
		||||
            const mapping = json.mappings[i]
 | 
			
		||||
            const tagIf = TagUtils.Tag(mapping.if, context.path.join("."))
 | 
			
		||||
            const optimized = new And([tagIf, condition]).optimize()
 | 
			
		||||
            if(optimized === false){
 | 
			
		||||
                const msg = ("Detected a conflicting mapping and condition. The mapping requires tags " + tagIf.asHumanString() + ", yet this can never happen because the set condition requires " + condition.asHumanString())
 | 
			
		||||
            if (optimized === false) {
 | 
			
		||||
                const msg =
 | 
			
		||||
                    "Detected a conflicting mapping and condition. The mapping requires tags " +
 | 
			
		||||
                    tagIf.asHumanString() +
 | 
			
		||||
                    ", yet this can never happen because the set condition requires " +
 | 
			
		||||
                    condition.asHumanString()
 | 
			
		||||
                const ctx = context.enters("mappings", i)
 | 
			
		||||
                if (this._forceError) {
 | 
			
		||||
                    ctx.err(msg)
 | 
			
		||||
| 
						 | 
				
			
			@ -615,10 +623,8 @@ export class DetectMappingsShadowedByCondition extends DesugaringStep<TagRenderi
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        return undefined
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class DetectShadowedMappings extends DesugaringStep<TagRenderingConfigJson> {
 | 
			
		||||
| 
						 | 
				
			
			@ -1094,14 +1100,26 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
 | 
			
		|||
                        )
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if(this._layerConfig?.source?.osmTags && NameSuggestionIndex.supportedTypes().indexOf(json.freeform.key) >= 0){
 | 
			
		||||
                const tags=  TagUtils.TagD(this._layerConfig?.source?.osmTags)?.usedTags()
 | 
			
		||||
            if (
 | 
			
		||||
                this._layerConfig?.source?.osmTags &&
 | 
			
		||||
                NameSuggestionIndex.supportedTypes().indexOf(json.freeform.key) >= 0
 | 
			
		||||
            ) {
 | 
			
		||||
                const tags = TagUtils.TagD(this._layerConfig?.source?.osmTags)?.usedTags()
 | 
			
		||||
                const suggestions = NameSuggestionIndex.getSuggestionsFor(json.freeform.key, tags)
 | 
			
		||||
                if(suggestions === undefined){
 | 
			
		||||
                    context.enters("freeform","type").err("No entry found in the 'Name Suggestion Index'. None of the 'osmSource'-tags match an entry in the NSI.\n\tOsmSource-tags are "+tags.map(t => t.asHumanString()).join(" ; "))
 | 
			
		||||
                if (suggestions === undefined) {
 | 
			
		||||
                    context
 | 
			
		||||
                        .enters("freeform", "type")
 | 
			
		||||
                        .err(
 | 
			
		||||
                            "No entry found in the 'Name Suggestion Index'. None of the 'osmSource'-tags match an entry in the NSI.\n\tOsmSource-tags are " +
 | 
			
		||||
                                tags.map((t) => t.asHumanString()).join(" ; ")
 | 
			
		||||
                        )
 | 
			
		||||
                }
 | 
			
		||||
            }else if(json.freeform.type === "nsi"){
 | 
			
		||||
                context.enters("freeform","type").warn("No need to explicitly set type to 'NSI', autodetected based on freeform type")
 | 
			
		||||
            } else if (json.freeform.type === "nsi") {
 | 
			
		||||
                context
 | 
			
		||||
                    .enters("freeform", "type")
 | 
			
		||||
                    .warn(
 | 
			
		||||
                        "No need to explicitly set type to 'NSI', autodetected based on freeform type"
 | 
			
		||||
                    )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (json.render && json["question"] && json.freeform === undefined) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1720,8 +1738,12 @@ export class ValidateLayer extends Conversion<
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(json.allowMove?.["enableAccuraccy"] !== undefined){
 | 
			
		||||
            context.enters("allowMove", "enableAccuracy").err("`enableAccuracy` is written with two C in the first occurrence and only one in the last")
 | 
			
		||||
        if (json.allowMove?.["enableAccuraccy"] !== undefined) {
 | 
			
		||||
            context
 | 
			
		||||
                .enters("allowMove", "enableAccuracy")
 | 
			
		||||
                .err(
 | 
			
		||||
                    "`enableAccuracy` is written with two C in the first occurrence and only one in the last"
 | 
			
		||||
                )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return { raw: json, parsed: layerConfig }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue