forked from MapComplete/MapComplete
Improve shadowing detection of mappings
This commit is contained in:
parent
363803fc45
commit
125b63927d
1 changed files with 22 additions and 10 deletions
|
@ -248,9 +248,19 @@ export class DetectShadowedMappings extends DesugaringStep<TagRenderingConfigJso
|
||||||
if (json.mappings === undefined || json.mappings.length === 0) {
|
if (json.mappings === undefined || json.mappings.length === 0) {
|
||||||
return {result: json}
|
return {result: json}
|
||||||
}
|
}
|
||||||
const parsedConditions = json.mappings.map(m => TagUtils.Tag(m.if))
|
const parsedConditions = json.mappings.map(m => {
|
||||||
|
const ifTags = TagUtils.Tag(m.if);
|
||||||
|
if(m.hideInAnswer !== undefined && m.hideInAnswer !== false && m.hideInAnswer !== true){
|
||||||
|
let conditionTags = TagUtils.Tag( m.hideInAnswer)
|
||||||
|
// Merge the condition too!
|
||||||
|
return new And([conditionTags, ifTags])
|
||||||
|
}
|
||||||
|
return ifTags
|
||||||
|
})
|
||||||
for (let i = 0; i < json.mappings.length; i++) {
|
for (let i = 0; i < json.mappings.length; i++) {
|
||||||
if(json.mappings[i].hideInAnswer === true){
|
if(!parsedConditions[i].isUsableAsAnswer()){
|
||||||
|
// There is no straightforward way to convert this mapping.if into a properties-object, so we simply skip this one
|
||||||
|
// Yes, it might be shadowed, but running this check is to difficult right now
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const keyValues = parsedConditions[i].asChange({});
|
const keyValues = parsedConditions[i].asChange({});
|
||||||
|
@ -259,14 +269,11 @@ export class DetectShadowedMappings extends DesugaringStep<TagRenderingConfigJso
|
||||||
properties[k] = v
|
properties[k] = v
|
||||||
})
|
})
|
||||||
for (let j = 0; j < i; j++) {
|
for (let j = 0; j < i; j++) {
|
||||||
if(json.mappings[j].hideInAnswer === true){
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const doesMatch = parsedConditions[j].matchesProperties(properties)
|
const doesMatch = parsedConditions[j].matchesProperties(properties)
|
||||||
if (doesMatch) {
|
if (doesMatch) {
|
||||||
// The current mapping is shadowed!
|
// The current mapping is shadowed!
|
||||||
errors.push(`At ${context}: Mapping ${i} is shadowed by mapping ${j} and will thus never be shown:
|
errors.push(`At ${context}: Mapping ${i} is shadowed by mapping ${j} and will thus never be shown:
|
||||||
The mapping ${parsedConditions[i].asHumanString(false, false, {})} is fully matched by a previous mapping, which matches:
|
The mapping ${parsedConditions[i].asHumanString(false, false, {})} is fully matched by a previous mapping (namely ${j}), which matches:
|
||||||
${parsedConditions[j].asHumanString(false, false, {})}.
|
${parsedConditions[j].asHumanString(false, false, {})}.
|
||||||
|
|
||||||
Move the mapping up to fix this problem
|
Move the mapping up to fix this problem
|
||||||
|
@ -276,6 +283,10 @@ export class DetectShadowedMappings extends DesugaringStep<TagRenderingConfigJso
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO make this errors again
|
||||||
|
warnings.push(...errors)
|
||||||
|
errors.splice(0, errors.length)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors,
|
errors,
|
||||||
warnings,
|
warnings,
|
||||||
|
@ -315,7 +326,9 @@ export class DetectMappingsWithImages extends DesugaringStep<TagRenderingConfigJ
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors,warnings,information,
|
errors,
|
||||||
|
warnings,
|
||||||
|
information,
|
||||||
result: json
|
result: json
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -324,8 +337,7 @@ export class DetectMappingsWithImages extends DesugaringStep<TagRenderingConfigJ
|
||||||
export class ValidateTagRenderings extends Fuse<TagRenderingConfigJson> {
|
export class ValidateTagRenderings extends Fuse<TagRenderingConfigJson> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("Various validation on tagRenderingConfigs",
|
super("Various validation on tagRenderingConfigs",
|
||||||
// TODO enable these checks again
|
new DetectShadowedMappings(),
|
||||||
// new DetectShadowedMappings(),
|
|
||||||
new DetectMappingsWithImages()
|
new DetectMappingsWithImages()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue