From 2b1e37ab78caca2d026391411ced6b3e114fe466 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 2 Sep 2018 12:25:36 +0100 Subject: [PATCH] Handle simple error descriptions explicitly This adds a flag to the error schema to explicitly say whether to parse the description with regex or not. Prevents us from having to escape special characters in fixed strings and is a minor optimisation. --- modules/util/keepRight/errorSchema.json | 159 ++++++++++++++-------- modules/util/keepRight/keepRight_error.js | 3 + 2 files changed, 108 insertions(+), 54 deletions(-) diff --git a/modules/util/keepRight/errorSchema.json b/modules/util/keepRight/errorSchema.json index d1ee09d7e..8c4e4c1c9 100644 --- a/modules/util/keepRight/errorSchema.json +++ b/modules/util/keepRight/errorSchema.json @@ -4,17 +4,20 @@ "errors": { "_30": { "title": "non-closed_areas", - "description": "This way is tagged with ''([\\w:]+)=(\\w+)''and should be closed-loop" + "description": "This way is tagged with ''([\\w:]+)=(\\w+)''and should be closed-loop", + "regex": true }, "_40": { "title": "dead-ended one-ways", "description": "The first node \\(id (\\d+)\\) of this one-way is not connected to any other way", - "IDs": ["n"] + "IDs": ["n"], + "regex": true }, "_41": { "title": "", "description": "The last node \\(id (\\d+)\\) of this one-way is not connected to any other way", - "IDs": ["n"] + "IDs": ["n"], + "regex": true }, "_42": { "title": "", @@ -27,11 +30,13 @@ "_50": { "title": "almost-junctions", "description": "This node is very close but not connected to way #(\\d+)", - "IDs": ["w"] + "IDs": ["w"], + "regex": true }, "_70": { "title": "missing tags", - "description": "This (node|way|relation) has an empty tag: "([\\w:]+)="" + "description": "This (node|way|relation) has an empty tag: "([\\w:]+)="", + "regex": true }, "_71": { "title": "", @@ -47,11 +52,13 @@ }, "_100": { "title": "places of worship without religion", - "description": "This (node|way|relation) is tagged as place of worship and therefore needs a religion tag" + "description": "This (node|way|relation) is tagged as place of worship and therefore needs a religion tag", + "regex": true }, "_110": { "title": "point of interest without name", - "description": "This node is tagged as ([\\w:]+) and therefore needs a name tag" + "description": "This node is tagged as ([\\w:]+) and therefore needs a name tag", + "regex": true }, "_120": { "title": "ways without nodes", @@ -71,7 +78,8 @@ }, "_170": { "title": "FIXME tagged items", - "description": "(.*)" + "description": "(.*)", + "regex": true }, "_180": { "title": "relations without type", @@ -84,42 +92,50 @@ "_191": { "title": "highway-highway", "description": "This (highway) intersects the (highway) #(\\d+) but there is no junction node", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_192": { "title": "highway-waterway", "description": "This (highway|waterway) intersects the (highway|waterway) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_193": { "title": "highway-riverbank", "description": "This (highway|riverbank) intersects the (highway|riverbank) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_194": { "title": "waterway-waterway", "description": "This (waterway) intersects the (waterway) #(\\d+) but there is no junction node", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_195": { "title": "cycleway-cycleway", "description": "This (cycleway/footpath) intersects the (cycleway/footpath) #(\\d+) but there is no junction node", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_196": { "title": "highway-cycleway", "description": "This (highway|cycleway/footpath) intersects the (highway|cycleway/footpath) #(\\d+) but there is no junction node", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_197": { "title": "cycleway-waterway", "description": "This (waterway|cycleway/footpath) intersects the (waterway|cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_198": { "title": "cycleway-riverbank", "description": "This (riverbank|cycleway/footpath) intersects the (riverbank|cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_200": { "title": "overlapping ways", @@ -128,42 +144,50 @@ "_201": { "title": "highway-highway", "description": "This (highway) overlaps the (highway) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_202": { "title": "highway-waterway", "description": "This (highway|waterway) overlaps the (highway|waterway) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_203": { "title": "highway-riverbank", "description": "This (highway|riverbank) overlaps the (highway|riverbank) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_204": { "title": "waterway-waterway", "description": "This (waterway) overlaps the (waterway) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_205": { "title": "cycleway-cycleway", "description": "This (cycleway/footpath) overlaps the (cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_206": { "title": "highway-cycleway", "description": "This (highway|cycleway/footpath) overlaps the (highway|cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_207": { "title": "cycleway-waterway", "description": "This (waterway|cycleway/footpath) overlaps the (waterway|cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_208": { "title": "cycleway-riverbank", "description": "This (riverbank|cycleway/footpath) overlaps the (riverbank|cycleway/footpath) #(\\d+)", - "IDs": ["", "", "w"] + "IDs": ["", "", "w"], + "regex": true }, "_210": { "title": "loopings", @@ -172,8 +196,9 @@ "_211": { "title": "", "description": "This way contains more than one node at least twice. Nodes are #(\\d+), ((?:#\\d+(?:, )?)+)\\. This may or may not be an error", - "IDs": ["n", ""], - "TODO": "Second group is arbitrary list of node IDs in form: #ID, #ID, #ID..." + "IDs": ["n"], + "TODO": "Second group is arbitrary list of node IDs in form: #ID, #ID, #ID...", + "regex": true }, "_212": { "title": "", @@ -181,11 +206,13 @@ }, "_220": { "title": "misspelled tags", - "description": "This (node|way|relation) is tagged '([\\w:]+)=(.+)' where "(\\2|\\3)" looks like "([\\w\\s]+)"" + "description": "This (node|way|relation) is tagged '([\\w:]+)=(.+)' where "(\\2|\\3)" looks like "([\\w\\s]+)"", + "regex": true }, "_221": { "title": "", - "description": "The key of this (node|way|relation)''s tag is ''key'': key=(.+)" + "description": "The key of this (node|way|relation)''s tag is ''key'': key=(.+)", + "regex": true }, "_230": { "title": "layer conflicts", @@ -194,11 +221,13 @@ "_231": { "title": "mixed layers intersection", "description": "This node is a junction of ways on different layers: ((?:#\\d+\\(-?\\d+\\),?)+)", - "IDs": ["231"] + "IDs": ["231"], + "regex": true }, "_232": { "title": "strange layers", - "description": "This (bridge|tunnel) is tagged with layer (-?\\d+)\\. This need not be an error but it looks strange" + "description": "This (bridge|tunnel) is tagged with layer (-?\\d+)\\. This need not be an error but it looks strange", + "regex": true }, "_270": { "title": "motorways connected directly", @@ -214,19 +243,23 @@ }, "_282": { "title": "missing admin level", - "description": "The boundary of (.+) has no (?:valid numeric )?admin_level\\..*" + "description": "The boundary of (.+) has no (?:valid numeric )?admin_level\\..*", + "regex": true }, "_283": { "title": "no closed loop", - "description": "The boundary of (.+) is not closed-loop" + "description": "The boundary of (.+) is not closed-loop", + "regex": true }, "_284": { "title": "splitting boundary", - "description": "The boundary of (.+) splits here" + "description": "The boundary of (.+) splits here", + "regex": true }, "_285": { "title": "admin_level too high", - "description": "This boundary-way has admin_level (-?\\d+) but belongs to a relation with lower admin_level (higher priority); it should have the lowest admin_level of all relations" + "description": "This boundary-way has admin_level (-?\\d+) but belongs to a relation with lower admin_level (higher priority); it should have the lowest admin_level of all relations", + "regex": true }, "_290": { "title": "restrictions", @@ -234,39 +267,47 @@ }, "_291": { "title": "missing type", - "description": "This turn-restriction has no (?:known )?restriction type" + "description": "This turn-restriction has no (?:known )?restriction type", + "regex": true }, "_292": { "title": "missing from way", - "description": "A turn-restriction needs exactly one from member\\. This one has (\\d+)" + "description": "A turn-restriction needs exactly one from member\\. This one has (\\d+)", + "regex": true }, "_293": { "title": "missing to way", - "description": "A turn-restriction needs exactly one to member\\. This one has (\\d+)" + "description": "A turn-restriction needs exactly one to member\\. This one has (\\d+)", + "regex": true }, "_294": { "title": "from or to not a way", "description": "From- and To-members of turn restrictions need to be ways\\. (.+)", - "TODO": "Group can be any combination of to/from: to node #ID | from node #ID | to relation #ID | from relation #ID" + "TODO": "Group can be any combination of to/from: to node #ID | from node #ID | to relation #ID | from relation #ID", + "regex": true }, "_295": { "title": "via is not on the way ends", "description": "via \\(node #(\\d+)\\) is not the first or the last member of from \\(way #(\\d+)\\)", - "IDs": ["n", "w"] + "IDs": ["n", "w"], + "regex": true }, "_296": { "title": "wrong restriction angle", - "description": "restriction type is (\\w+) but angle is (\\d+) degrees. Maybe the restriction type is not appropriate?" + "description": "restriction type is (\\w+) but angle is (\\d+) degrees. Maybe the restriction type is not appropriate?", + "regex": true }, "_297": { "title": "wrong direction of to member", "description": "wrong direction of to way (\\d+)", - "IDs": ["w"] + "IDs": ["w"], + "regex": true }, "_298": { "title": "already restricted by oneway", "description": "entry already prohibited by oneway tag on (\\d+)", - "IDs": ["w"] + "IDs": ["w"], + "regex": true }, "_310": { "title": "roundabouts", @@ -274,33 +315,39 @@ }, "_311": { "title": "not closed loop", - "description": "This way is part of a roundabout but is not closed-loop\\. \\(split carriageways approaching a roundabout should not be tagged as roundabout\\)" + "description": "This way is part of a roundabout but is not closed-loop. (split carriageways approaching a roundabout should not be tagged as roundabout)" }, "_312": { "title": "wrong direction", - "description": "If this ((?:mini_)?roundabout) is in a country with (left|right)-hand traffic then its orientation goes the wrong way around" + "description": "If this ((?:mini_)?roundabout) is in a country with (left|right)-hand traffic then its orientation goes the wrong way around", + "regex": true }, "_313": { "title": "faintly connected", - "description": "This roundabout has only (\\d) other roads connected. Roundabouts typically have three" + "description": "This roundabout has only (\\d) other roads connected. Roundabouts typically have three", + "regex": true }, "_320": { "title": "*_link connections", - "description": "This way is tagged as highway=(\\w+)_link but doesn''t have a connection to any other \\1 or \\1_link" + "description": "This way is tagged as highway=(\\w+)_link but doesn''t have a connection to any other \\1 or \\1_link", + "regex": true }, "_350": { "title": "bridge-tags", "description": "This bridge does not have a tag in common with its surrounding ways that shows the purpose of this bridge. There should be one of these tags: (.+)", - "NOTE": "Group can be arbitrary list of form: key=value,key=value,key=value..." + "NOTE": "Group can be arbitrary list of form: key=value,key=value,key=value...", + "regex": true }, "_370": { "title": "doubled places", "description": "This node has tags in common with the surrounding way #(\\d+) ((?:\\(including the name '.+'\\) )?)and seems to be redundand", - "IDs": ["w", ""] + "IDs": ["w"], + "regex": true }, "_380": { "title": "non-physical use of sport-tag", - "description": "This way is tagged sport=(\\w+) but has no physical tag like e.g. leisure, building, amenity or highway" + "description": "This way is tagged sport=(\\w+) but has no physical tag like e.g. leisure, building, amenity or highway", + "regex": true }, "_400": { "title": "geometry glitches", @@ -309,7 +356,8 @@ "_401": { "title": "missing turn restriction", "description": "ways (\\d+) and (\\d+) join in a very sharp angle here and there is no oneway tag or turn restriction that prevents turning from way (\\1|\\2) to (\\1|\\2)", - "IDs": ["w", "w", "w", "w"] + "IDs": ["w", "w", "w", "w"], + "regex": true }, "_402": { "title": "impossible angles", @@ -322,15 +370,17 @@ "_411": { "title": "http error", "description": "The URL \\(\\1\\) cannot be opened \\(HTTP status code (\\d+)\\)", - "NOTE": "It seems the HTML attributes don't have quotes when the code reads them" + "regex": true }, "_412": { "title": "domain hijacking", - "description": "Possible domain squatting: \\1. Suspicious text is: ''(.+)''" + "description": "Possible domain squatting: \\1. Suspicious text is: ''(.+)''", + "regex": true }, "_413": { "title": "non-match", - "description": "Content of the URL (\\1) did not contain these keywords: \\((.+)\\)" + "description": "Content of the URL (\\1) did not contain these keywords: \\((.+)\\)", + "regex": true } }, "warnings": { @@ -348,7 +398,8 @@ }, "_360": { "title": "language unknown", - "description": "It would be nice if this (node|way|relation) had an additional tag ''name:XX=(\\.+?)''where XX shows the language of its name ''\\2''" + "description": "It would be nice if this (node|way|relation) had an additional tag ''name:XX=(\\.+?)''where XX shows the language of its name ''\\2''", + "regex": true }, "_390": { "title": "missing tracktype", diff --git a/modules/util/keepRight/keepRight_error.js b/modules/util/keepRight/keepRight_error.js index e2c3a23f3..887a607e1 100644 --- a/modules/util/keepRight/keepRight_error.js +++ b/modules/util/keepRight/keepRight_error.js @@ -104,6 +104,9 @@ export function parseErrorDescriptions(entity) { errorTemplate = errorTypes.errors[errorType] || errorTypes.warnings[errorType]; if (!errorTemplate) return; + // some descriptions are just fixed text + if (!('regex' in errorTemplate)) return; + // regex pattern should match description with variable details captured as groups errorDescription = entity.description; errorRegex = new RegExp(errorTemplate.description);