From 9557c0204a2c024c1561450e799a7c1f0264fd99 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 2 Jan 2019 13:39:21 -0500 Subject: [PATCH] Relax some more regex for tag parsing, (to support 'key=*') Also implement parsing error 231 - layer conflict --- data/core.yaml | 7 +- data/keepRight.json | 138 ++++---------------------------- dist/locales/en.json | 9 ++- modules/services/keepRight.js | 34 +++----- modules/ui/keepRight_details.js | 11 +-- modules/ui/keepRight_header.js | 11 +-- 6 files changed, 39 insertions(+), 171 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 749b48fd1..699e272d2 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -673,7 +673,7 @@ en: description: 'There is more than one node in this spot. Node IDs: {var1}.' 30: title: 'Non-closed areas' - description: 'This way is tagged with "{var1}={var2}" and should be a closed loop.' + description: 'This way is tagged with "{var1}" and should be a closed loop.' 40: title: 'Impossible oneways' description: 'The first node {var1} of this oneway is not connected to any other way.' @@ -688,7 +688,7 @@ en: description: 'This node is very close but not connected to way {var1}.' 60: title: 'Deprecated tags' - description: 'This {var1} uses deprecated tag "{var2}={var3}". Please use "{var4}" instead.' + description: 'This {var1} uses deprecated tag "{var2}". Please use "{var3}" instead.' 70: title: 'Missing tags' description: 'This {var1} has an empty tag: "{var2}".' @@ -752,6 +752,7 @@ en: description: 'This node is a junction of ways on different layers.' 231: description: 'This node is a junction of ways on different layers: {var1}.' + layer: '(layer: {layer})' 232: description: 'This {var1} is tagged with "layer={var2}". This need not be an error but it looks strange.' 270: @@ -792,7 +793,7 @@ en: description: '"from" and "to" members of turn restrictions need to be ways. {var1}.' 295: title: 'Restriction "via" is not on the way ends' - description: '"via" (node {var1}) is not the first or the last member of "from" (way {var2}).' + description: '"via" (node {var1}) is not the first or the last member of "{var2}" (way {var3}).' 296: title: 'Wrong restriction angle' description: 'Restriction type is "{var1}" but angle is {var2} degrees. Maybe the restriction type is not appropriate?' diff --git a/data/keepRight.json b/data/keepRight.json index b598ecb74..cf9b3fcb7 100644 --- a/data/keepRight.json +++ b/data/keepRight.json @@ -10,8 +10,8 @@ "30": { "title": "non-closed_areas", "severity": "error", - "description": "This way is tagged with '$1=$2' and should be closed-loop.", - "regex": "'([\\w:]+)=(\\w+)'" + "description": "This way is tagged with '$1' and should be closed-loop.", + "regex": "'(.+)'" }, "40": { "title": "dead-ended one-ways", @@ -47,8 +47,8 @@ "60": { "title": "depreciated tags", "severity": "warning", - "description": "This $1 uses deprecated tag $2 = $3. Please use $4 instead!", - "regex": "This (node|way|relation) uses deprecated tag '([\\w:]+)=(.+)'\\. Please use "(.+)" instead" + "description": "This $1 uses deprecated tag $2. Please use $3 instead!", + "regex": "This (node|way|relation) uses deprecated tag '(.+)'\\. Please use "(.+)"" }, "70": { "title": "missing tags", @@ -74,11 +74,11 @@ "title": "missing tags", "severity": "error", "description": "This $1 has an empty tag: $2", - "regex": "This (node|way|relation) has an empty tag: "([\\w:]+)="" + "regex": "This (node|way|relation) has an empty tag: "(.+)="" }, "75": { "description": "This (node|way|relation) has a name \\((.+)\\) but no other tag", - "regex": "This (node|way|relation) has a name \\((.+)\\) but no other tag" + "regex": "This (node|way|relation) has a name \\((.+)\\)" }, "90": { "title": "motorways without ref", @@ -95,7 +95,7 @@ "title": "point of interest without name", "severity": "error", "description": "This node is tagged as $1 and therefore needs a name tag", - "regex": "as ([\\w:]+) and" + "regex": "as (.+) and" }, "120": { "title": "ways without nodes", @@ -131,124 +131,16 @@ "190": { "title": "intersections without junctions", "severity": "error", - "description": "Finds way crossings on same layer without common node as a junction" - }, - "191": { - "title": "highway-highway", - "severity": "error", - "description": "This (highway) intersects the (highway) #(\\d+) but there is no junction node", + "description": "This $1 intersects the $2 #$3 but there is no junction node", "IDs": ["", "", "w"], - "regex": "This (highway) intersects the (highway) #(\\d+) but" - }, - "192": { - "title": "highway-waterway", - "severity": "error", - "description": "This (highway|waterway) intersects the (highway|waterway) #(\\d+)", - "IDs": ["", "", "w"], - "regex": "This (highway|waterway) intersects the (highway|waterway) #(\\d+)" - }, - "193": { - "title": "highway-riverbank", - "severity": "error", - "description": "This (highway|riverbank) intersects the (highway|riverbank) #(\\d+)", - "IDs": ["", "", "w"], - "regex": "This (highway|riverbank) intersects the (highway|riverbank) #(\\d+)" - }, - "194": { - "title": "waterway-waterway", - "severity": "error", - "description": "This (waterway) intersects the (waterway) #(\\d+) but there is no junction node", - "IDs": ["", "","w"], - "regex": "This (waterway) intersects the (waterway) #(\\d+) but there is no junction node" - }, - "195": { - "title": "cycleway-cycleway", - "severity": "error", - "description": "This (cycleway/footpath) intersects the (cycleway/footpath) #(\\d+) but there is no junction node", - "IDs": ["", "","w"], - "regex": "This (cycleway/footpath) intersects the (cycleway/footpath) #(\\d+) but there is no junction node" - }, - "196": { - "title": "highway-cycleway", - "severity": "error", - "description": "This (highway|cycleway/footpath) intersects the (highway|cycleway/footpath) #(\\d+) but there is no junction node", - "IDs": ["", "","w"], - "regex": "This (highway|cycleway/footpath) intersects the (highway|cycleway/footpath) #(\\d+) but there is no junction node" - }, - "197": { - "title": "cycleway-waterway", - "severity": "error", - "description": "This (waterway|cycleway/footpath) intersects the (waterway|cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (waterway|cycleway/footpath) intersects the (waterway|cycleway/footpath) #(\\d+)" - }, - "198": { - "title": "cycleway-riverbank", - "severity": "error", - "description": "This (riverbank|cycleway/footpath) intersects the (riverbank|cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (riverbank|cycleway/footpath) intersects the (riverbank|cycleway/footpath) #(\\d+)" + "regex": "This (.+) intersects the (.+) #(\\d+)" }, "200": { "title": "overlapping ways", "severity": "error", - "description": "Finds overlapping ways on same layer" - }, - "201": { - "title": "highway-highway", - "severity": "error", - "description": "This (highway) overlaps the (highway) #(\\d+)", "IDs": ["", "","w"], - "regex": "This (highway) overlaps the (highway) #(\\d+)" - }, - "202": { - "title": "highway-waterway", - "severity": "error", - "description": "This (highway|waterway) overlaps the (highway|waterway) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (highway|waterway) overlaps the (highway|waterway) #(\\d+)" - }, - "203": { - "title": "highway-riverbank", - "severity": "error", - "description": "This (highway|riverbank) overlaps the (highway|riverbank) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (highway|riverbank) overlaps the (highway|riverbank) #(\\d+)" - }, - "204": { - "title": "waterway-waterway", - "severity": "error", - "description": "This (waterway) overlaps the (waterway) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (waterway) overlaps the (waterway) #(\\d+)" - }, - "205": { - "title": "cycleway-cycleway", - "severity": "error", - "description": "This (cycleway/footpath) overlaps the (cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (cycleway/footpath) overlaps the (cycleway/footpath) #(\\d+)" - }, - "206": { - "title": "highway-cycleway", - "severity": "error", - "description": "This (highway|cycleway/footpath) overlaps the (highway|cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (highway|cycleway/footpath) overlaps the (highway|cycleway/footpath) #(\\d+)" - }, - "207": { - "title": "cycleway-waterway", - "severity": "error", - "description": "This (waterway|cycleway/footpath) overlaps the (waterway|cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (waterway|cycleway/footpath) overlaps the (waterway|cycleway/footpath) #(\\d+)" - }, - "208": { - "title": "cycleway-riverbank", - "severity": "error", - "description": "This (riverbank|cycleway/footpath) overlaps the (riverbank|cycleway/footpath) #(\\d+)", - "IDs": ["", "","w"], - "regex": "This (riverbank|cycleway/footpath) overlaps the (riverbank|cycleway/footpath) #(\\d+)" + "description": "This $1 overlaps the $2 #$3", + "regex": "This (.+) overlaps the (.+) #(\\d+)" }, "210": { "title": "loopings", @@ -289,7 +181,7 @@ "severity": "error", "description": "This node is a junction of ways on different layers: $1", "IDs": ["231"], - "regex": "layers: ((?:#\\d+\\(-?\\d+\\),?)+)" + "regex": "layers: (.+)" }, "232": { "title": "strange layers", @@ -369,9 +261,9 @@ "295": { "title": "via is not on the way ends", "severity": "error", - "description": "via (node #$1) is not the first or the last member of from (way #$2)", + "description": "via (node #$1) is not the first or the last member of (from|to) (way #$3)", "IDs": ["n","w"], - "regex": "via \\(node #(\\d+)\\) is not the first or the last member of from \\(way #(\\d+)\\)" + "regex": "via \\(node #(\\d+)\\) is not the first or the last member of (from|to) \\(way #(\\d+)\\)" }, "296": { "title": "wrong restriction angle", @@ -412,7 +304,7 @@ "title": "wrong direction", "severity": "error", "description": "If this ((?:mini_)?roundabout) is in a country with (left|right)-hand traffic then its orientation goes the wrong way around", - "regex": "If this ((?:mini_)?roundabout) is in a country with (left|right)-hand traffic then its orientation goes the wrong way around" + "regex": "this ((?:mini_)?roundabout) is in a country with (left|right)-hand" }, "313": { "title": "faintly connected", diff --git a/dist/locales/en.json b/dist/locales/en.json index 546019cf7..d06031da9 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -815,7 +815,7 @@ }, "30": { "title": "Non-closed areas", - "description": "This way is tagged with \"{var1}={var2}\" and should be a closed loop." + "description": "This way is tagged with \"{var1}\" and should be a closed loop." }, "40": { "title": "Impossible oneways", @@ -836,7 +836,7 @@ }, "60": { "title": "Deprecated tags", - "description": "This {var1} uses deprecated tag \"{var2}={var3}\". Please use \"{var4}\" instead." + "description": "This {var1} uses deprecated tag \"{var2}\". Please use \"{var3}\" instead." }, "70": { "title": "Missing tags", @@ -923,7 +923,8 @@ "description": "This node is a junction of ways on different layers." }, "231": { - "description": "This node is a junction of ways on different layers: {var1}." + "description": "This node is a junction of ways on different layers: {var1}.", + "layer": "(layer: {layer})" }, "232": { "description": "This {var1} is tagged with \"layer={var2}\". This need not be an error but it looks strange." @@ -978,7 +979,7 @@ }, "295": { "title": "Restriction \"via\" is not on the way ends", - "description": "\"via\" (node {var1}) is not the first or the last member of \"from\" (way {var2})." + "description": "\"via\" (node {var1}) is not the first or the last member of \"{var2}\" (way {var3})." }, "296": { "title": "Wrong restriction angle", diff --git a/modules/services/keepRight.js b/modules/services/keepRight.js index 92e0fc3a7..0730695ca 100644 --- a/modules/services/keepRight.js +++ b/modules/services/keepRight.js @@ -120,7 +120,7 @@ function tokenReplacements(d) { function parseError(group, idType) { - function fillPlaceholder(d) { + function linkEntity(d) { return '' + d + ''; } @@ -131,7 +131,7 @@ function parseError(group, idType) { items.forEach(function(item) { // ID has # at the front - var id = fillPlaceholder('n' + item.slice(1)); + var id = linkEntity('n' + item.slice(1)); newList.push(id); }); @@ -141,24 +141,16 @@ function parseError(group, idType) { // arbitrary way list of form: #ID(layer),#ID(layer),#ID(layer)... function parseError231(list) { var newList = []; - var items = list.split(','); + // unfortunately 'layer' can itself contain commas, so we split on '),' + 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); - - // TODO: translation - newList.push(id + ' (layer: ' + layer + ')'); + var match = item.match(/\#(\d+)\((.+)\)?/); + if (match !== null && match.length > 2) { + newList.push(linkEntity('w' + match[1]) + + t('QA.keepRight.errorTypes.231.layer', { layer: match[2] }) + ); + } }); return newList.join(', '); @@ -185,7 +177,7 @@ function parseError(group, idType) { // ID has # at the front id = item[2].slice(1); - id = fillPlaceholder(idType + id); + id = linkEntity(idType + id); item = [role, item[1], id].join(' '); newList.push(item); @@ -201,7 +193,7 @@ function parseError(group, idType) { items.forEach(function(item) { // ID has # at the front - var id = fillPlaceholder('n' + item.slice(1)); + var id = linkEntity('n' + item.slice(1)); newList.push(id); }); @@ -213,7 +205,7 @@ function parseError(group, idType) { case 'n': case 'w': case 'r': - group = fillPlaceholder(idType + group); + group = linkEntity(idType + group); break; // some errors have more complex ID lists/variance case '211': diff --git a/modules/ui/keepRight_details.js b/modules/ui/keepRight_details.js index a807b452f..a093ab3f7 100644 --- a/modules/ui/keepRight_details.js +++ b/modules/ui/keepRight_details.js @@ -14,16 +14,7 @@ export function uiKeepRightDetails(context) { if (!d) return unknown; var errorType = d.error_type; - - var template = errorTypes[errorType]; - if (!template) return unknown; - - // if there is a parent, save its error type e.g.: - // Error 191 = "highway-highway" - // Error 190 = "intersections without junctions" (parent) - var parentErrorType = (Math.floor(errorType / 10) * 10).toString(); - var parentTemplate = errorTypes[parentErrorType]; - if (!parentTemplate) return unknown; + var parentErrorType = d.parent_error_type var et = dataEn.QA.keepRight.errorTypes[errorType]; var pt = dataEn.QA.keepRight.errorTypes[parentErrorType]; diff --git a/modules/ui/keepRight_header.js b/modules/ui/keepRight_header.js index 261bc0268..b432c9fcc 100644 --- a/modules/ui/keepRight_header.js +++ b/modules/ui/keepRight_header.js @@ -13,16 +13,7 @@ export function uiKeepRightHeader() { if (!d) return unknown; var errorType = d.error_type; - - var template = errorTypes[errorType]; - if (!template) return unknown; - - // if there is a parent, save its error type e.g.: - // Error 191 = "highway-highway" - // Error 190 = "intersections without junctions" (parent) - var parentErrorType = (Math.floor(errorType / 10) * 10).toString(); - var parentTemplate = errorTypes[parentErrorType]; - if (!parentTemplate) return unknown; + var parentErrorType = d.parent_error_type var et = dataEn.QA.keepRight.errorTypes[errorType]; var pt = dataEn.QA.keepRight.errorTypes[parentErrorType];