From e0e48b75058c9903dde92113bcb7a2f276533448 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 2 Sep 2018 11:05:37 +0100 Subject: [PATCH] Fix parsing of error type 231 --- data/core.yaml | 2 +- modules/util/keepRight/errorSchema.json | 5 ++-- modules/util/keepRight/keepRight_error.js | 34 +++++++++++++++++++++-- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 908755cd7..164abb139 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1082,7 +1082,7 @@ en: description: '' _231: title: 'mixed layers intersection' - description: 'This node is a junction of ways on different layers: {var1}({var2}), {var3}.' + description: 'This node is a junction of ways on different layers: {var1}.' _232: title: 'strange layers' description: 'This {var1} is tagged with layer {var2}. This need not be an error but it looks strange.' diff --git a/modules/util/keepRight/errorSchema.json b/modules/util/keepRight/errorSchema.json index cd8a859fd..d1ee09d7e 100644 --- a/modules/util/keepRight/errorSchema.json +++ b/modules/util/keepRight/errorSchema.json @@ -193,9 +193,8 @@ }, "_231": { "title": "mixed layers intersection", - "description": "This node is a junction of ways on different layers: #(\\d+)\\((-?\\d+)\\),((?:#\\d+\\(-?\\d+\\),?)+)", - "IDs": ["w", ""], - "TODO": "Third group is arbitrary list of way IDs and their layer value in form: #ID(layer),#ID(layer),#ID(layer)..." + "description": "This node is a junction of ways on different layers: ((?:#\\d+\\(-?\\d+\\),?)+)", + "IDs": ["231"] }, "_232": { "title": "strange layers", diff --git a/modules/util/keepRight/keepRight_error.js b/modules/util/keepRight/keepRight_error.js index 6c5341036..0c8a92151 100644 --- a/modules/util/keepRight/keepRight_error.js +++ b/modules/util/keepRight/keepRight_error.js @@ -70,6 +70,31 @@ export function parseErrorDescriptions(entity) { function fillPlaceholder(d) { return '' + d + ''; } + // arbitrary list of way IDs and their layer value in form: #ID(layer),#ID(layer),#ID(layer)... + function parseError231(list) { + var newList = []; + var items = list.split(','); + + items.forEach(function(item) { + var id; + var layer; + + // item of form "#ID(layer)" + item = item.split('('); + + // ID has # at the front + id = item[0].slice(1); + id = fillPlaceholder('w' + id); + + // layer has trailing ) + layer = item[1].slice(0,-1); + + newList.push(id + ' (layer: ' + layer + ')'); + }); + + return newList.join(', '); + } + // regex pattern should capture groups to extract appropriate details var errorDescription = entity.description; var errorRe = new RegExp(matchingTemplate.description); @@ -89,12 +114,15 @@ export function parseErrorDescriptions(entity) { for (var i = 1; i < errorMatch.length; i++) { var group = errorMatch[i]; - // IDs captured have an associated type + // Clean and link IDs if present in the error if ('IDs' in matchingTemplate && matchingTemplate.IDs[i-1]) { var prefix = matchingTemplate.IDs[i-1]; - // wrap id with linking span if valid - if (['n','w','r'].includes(prefix)) { + // some errors have more complex ID lists/variance + if (prefix === '231') { + group = parseError231(group); + } else if (['n','w','r'].includes(prefix)) { + // wrap with linking span if simple case group = fillPlaceholder(prefix + group); } } else if (html_re.test(group)) {