From 14896b0ce56e09dbe147550a4d1ccb487e35e9b5 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 12 Feb 2019 16:07:08 -0500 Subject: [PATCH] Documentation, and move validation type up to top of each file --- modules/core/validator.js | 29 ++++++++++-------------- modules/validations/almost_junction.js | 7 +++--- modules/validations/crossing_ways.js | 6 +++-- modules/validations/deprecated_tag.js | 2 +- modules/validations/disconnected_way.js | 3 ++- modules/validations/generic_name.js | 3 ++- modules/validations/maprules.js | 4 +++- modules/validations/missing_tag.js | 5 ++-- modules/validations/tag_suggests_area.js | 1 + 9 files changed, 31 insertions(+), 29 deletions(-) diff --git a/modules/core/validator.js b/modules/core/validator.js index 5935733ce..8c95f2325 100644 --- a/modules/core/validator.js +++ b/modules/core/validator.js @@ -166,6 +166,15 @@ export function coreValidator(context) { export function validationIssue(attrs) { + this.type = attrs.type; // required + this.severity = attrs.severity; // required - 'warning' or 'error' + this.message = attrs.message; // required - localized string + this.tooltip = attrs.tooltip; // required - localized string + this.entities = attrs.entities; // optional - array of entities + this.coordinates = attrs.coordinates; // optional - expect a [lon, lat] array + this.info = attrs.info; // optional - object containing arbitrary extra information + this.fixes = attrs.fixes; // optional - array of validationIssueFix objects + this.hash = attrs.hash; // optional - string to further differentiate the issue // A unique, deterministic string hash. // Issues with identical id values are considered identical. @@ -189,15 +198,6 @@ export function validationIssue(attrs) { return id; }; - this.type = attrs.type; - this.severity = attrs.severity; - this.message = attrs.message; - this.tooltip = attrs.tooltip; - this.entities = attrs.entities; // expect an array of entities - this.coordinates = attrs.coordinates; // expect a [lon, lat] array - this.info = attrs.info; // an object containing arbitrary extra information - this.fixes = attrs.fixes; // expect an array of functions for possible fixes - this.hash = attrs.hash; // an optional string to further differentiate the issue this.loc = function() { if (this.coordinates && Array.isArray(this.coordinates) && this.coordinates.length === 2) { @@ -210,9 +210,8 @@ export function validationIssue(attrs) { }*/ }; - if (this.fixes) { + if (this.fixes) { // add a reference in the fixes to the issue for use in fix actions for (var i = 0; i < this.fixes.length; i++) { - // add a reference in the fix to the issue for use in fix actions this.fixes[i].issue = this; } } @@ -222,10 +221,6 @@ export function validationIssue(attrs) { export function validationIssueFix(attrs) { this.title = attrs.title; this.onClick = attrs.onClick; - - // IDs of fix-specific entities. Used for hover-higlighting. - this.entityIds = attrs.entityIds || []; - - // the issue this fix is for - this.issue = null; + this.entityIds = attrs.entityIds || []; // Used for hover-higlighting. + this.issue = null; // the issue this fix is for } diff --git a/modules/validations/almost_junction.js b/modules/validations/almost_junction.js index d8cbdb9e7..1b50b0e4f 100644 --- a/modules/validations/almost_junction.js +++ b/modules/validations/almost_junction.js @@ -20,6 +20,8 @@ import { validationIssue, validationIssueFix } from '../core/validator'; * Look for roads that can be connected to other roads with a short extension */ export function validationAlmostJunction() { + var type = 'almost_junction'; + function isHighway(entity) { return entity.type === 'way' && entity.tags.highway && entity.tags.highway !== 'no'; @@ -120,9 +122,6 @@ export function validationAlmostJunction() { } - var type = 'almost_junction'; - - var validation = function(endHighway, context) { if (!isHighway(endHighway)) return []; @@ -167,7 +166,7 @@ export function validationAlmostJunction() { onClick: function() { var nodeID = this.issue.entities[1].id; context.perform( - actionChangeTags(nodeID, {noexit: 'yes'}), + actionChangeTags(nodeID, { noexit: 'yes' }), t('issues.fix.tag_as_disconnected.annotation') ); } diff --git a/modules/validations/crossing_ways.js b/modules/validations/crossing_ways.js index e0cdc672b..21248d9a6 100644 --- a/modules/validations/crossing_ways.js +++ b/modules/validations/crossing_ways.js @@ -11,6 +11,9 @@ import { validationIssue, validationIssueFix } from '../core/validator'; export function validationCrossingWays() { + var type = 'crossing_ways'; + + // Check if the edge going from n1 to n2 crosses (without a connection node) // any edge on way. Return the cross point if so. function findEdgeToWayCrossCoords(n1, n2, way, graph) { @@ -271,8 +274,6 @@ export function validationCrossingWays() { return edgeCrossInfos; } - var type = 'crossing_ways'; - var validation = function(entity, context) { var graph = context.graph(); @@ -412,5 +413,6 @@ export function validationCrossingWays() { validation.type = type; + return validation; } diff --git a/modules/validations/deprecated_tag.js b/modules/validations/deprecated_tag.js index e12cbc380..a3da623c1 100644 --- a/modules/validations/deprecated_tag.js +++ b/modules/validations/deprecated_tag.js @@ -6,9 +6,9 @@ import { utilDisplayLabel, utilTagText } from '../util'; import { validationIssue, validationIssueFix } from '../core/validator'; export function validationDeprecatedTag() { - var type = 'deprecated_tag'; + var validation = function(entity, context) { var issues = []; var deprecatedTagsArray = entity.deprecatedTags(); diff --git a/modules/validations/disconnected_way.js b/modules/validations/disconnected_way.js index 2104b2d26..f864da0b6 100644 --- a/modules/validations/disconnected_way.js +++ b/modules/validations/disconnected_way.js @@ -6,6 +6,8 @@ import { validationIssue, validationIssueFix } from '../core/validator'; export function validationDisconnectedWay() { + var type = 'disconnected_way'; + function isDisconnectedHighway(entity, graph) { if (!entity.tags.highway) return false; @@ -25,7 +27,6 @@ export function validationDisconnectedWay() { }); } - var type = 'disconnected_way'; var validation = function(entity, context) { var issues = []; diff --git a/modules/validations/generic_name.js b/modules/validations/generic_name.js index 5212d8391..9c5293706 100644 --- a/modules/validations/generic_name.js +++ b/modules/validations/generic_name.js @@ -7,6 +7,8 @@ import { discardNames } from '../../node_modules/name-suggestion-index/config/fi export function validationGenericName(context) { + var type = 'generic_name'; + function isGenericName(entity) { var name = entity.tags.name; @@ -34,7 +36,6 @@ export function validationGenericName(context) { return false; } - var type = 'generic_name'; var validation = function(entity) { var issues = []; diff --git a/modules/validations/maprules.js b/modules/validations/maprules.js index 2b106b6a6..c5cd87014 100644 --- a/modules/validations/maprules.js +++ b/modules/validations/maprules.js @@ -2,6 +2,9 @@ import { services } from '../services'; export function validationMaprules() { + validation.type = 'maprules'; + + var validation = function(entity, context) { if (!services.maprules) return []; @@ -18,7 +21,6 @@ export function validationMaprules() { return issues; }; - validation.type = 'maprules'; return validation; } diff --git a/modules/validations/missing_tag.js b/modules/validations/missing_tag.js index 7015f392e..3ed4313a7 100644 --- a/modules/validations/missing_tag.js +++ b/modules/validations/missing_tag.js @@ -9,6 +9,8 @@ import { validationIssue, validationIssueFix } from '../core/validator'; export function validationMissingTag() { + var type = 'missing_tag'; + function hasDescriptiveTags(entity) { var keys = _without(Object.keys(entity.tags), 'area', 'name').filter(osmIsInterestingTag); @@ -18,7 +20,6 @@ export function validationMissingTag() { return keys.length > 0; } - var type = 'missing_tag'; var validation = function(entity, context) { var graph = context.graph(); @@ -52,7 +53,7 @@ export function validationMissingTag() { type: type, // error if created or modified, else warning severity: !entity.version || entity.v ? 'error' : 'warning', - message: t('issues.missing_tag.'+missingTagType+'.message', messageObj), + message: t('issues.missing_tag.' + missingTagType + '.message', messageObj), tooltip: t('issues.missing_tag.tip'), entities: [entity], fixes: [ diff --git a/modules/validations/tag_suggests_area.js b/modules/validations/tag_suggests_area.js index 926bacbe9..c9883803e 100644 --- a/modules/validations/tag_suggests_area.js +++ b/modules/validations/tag_suggests_area.js @@ -10,6 +10,7 @@ import { validationIssue, validationIssueFix } from '../core/validator'; export function validationTagSuggestsArea() { var type = 'tag_suggests_area'; + var validation = function(entity, context) { if (entity.type !== 'way') return [];