Move highway=road validation warning to the missing_tag validation rule (re: #6218)

This commit is contained in:
Quincy Morgan
2019-04-24 15:19:57 -07:00
parent b30c91828f
commit 13f7e536dc
8 changed files with 41 additions and 137 deletions
-2
View File
@@ -1398,9 +1398,7 @@ en:
tip: "Find features that are tagged as lines and should possibly be tagged as areas"
reference: "Areas must have connected endpoints."
unknown_road:
title: Unknown Roads
message: "{feature} has no classification"
tip: "Find roads that are missing a proper road classification"
reference: "Roads without a specific type may not appear in maps or routing."
unsquare_way:
title: Unsquare Buildings
-2
View File
@@ -1730,9 +1730,7 @@
"reference": "Areas must have connected endpoints."
},
"unknown_road": {
"title": "Unknown Roads",
"message": "{feature} has no classification",
"tip": "Find roads that are missing a proper road classification",
"reference": "Roads without a specific type may not appear in maps or routing."
},
"unsquare_way": {
-1
View File
@@ -10,5 +10,4 @@ export { validationOldMultipolygon } from './old_multipolygon';
export { validationOutdatedTags } from './outdated_tags';
export { validationPrivateData } from './private_data';
export { validationTagSuggestsArea } from './tag_suggests_area';
export { validationUnknownRoad } from './unknown_road';
export { validationUnsquareWay } from './unsquare_way';
+25 -9
View File
@@ -1,4 +1,4 @@
import { operationDelete } from '../operations/index';
import { operationDelete } from '../operations/delete';
import { osmIsInterestingTag } from '../osm/tags';
import { t } from '../util/locale';
import { utilDisplayLabel } from '../util';
@@ -26,6 +26,15 @@ export function validationMissingTag() {
}
function isUnknownRoad(entity) {
return entity.type === 'way' && entity.tags.highway === 'road';
}
function isUntypedRelation(entity) {
return entity.type === 'relation' && !entity.tags.type;
}
var validation = function checkMissingTag(entity, context) {
var graph = context.graph();
@@ -41,21 +50,23 @@ export function validationMissingTag() {
missingTagType = 'any';
} else if (!hasDescriptiveTags(entity)) {
missingTagType = 'descriptive';
} else if (entity.type === 'relation' && !entity.tags.type) {
} else if (isUntypedRelation(entity)) {
missingTagType = 'specific';
messageObj.tag = 'type';
} else if (isUnknownRoad(entity)) {
missingTagType = 'unknown_road';
}
if (!missingTagType) {
return [];
}
if (!missingTagType) return [];
messageObj.feature = utilDisplayLabel(entity, context);
var selectFixType = missingTagType === 'unknown_road' ? 'select_road_type' : 'select_preset';
var fixes = [
new validationIssueFix({
icon: 'iD-icon-search',
title: t('issues.fix.select_preset.title'),
title: t('issues.fix.' + selectFixType + '.title'),
onClick: function() {
context.ui().sidebar.showPresetList();
}
@@ -86,10 +97,15 @@ export function validationMissingTag() {
);
}
var messageID = missingTagType === 'unknown_road' ? 'unknown_road' : 'missing_tag.' + missingTagType;
var referenceID = missingTagType === 'unknown_road' ? 'unknown_road' : 'missing_tag';
var severity = (canDelete && missingTagType !== 'unknown_road') ? 'error' : 'warning';
return [new validationIssue({
type: type,
severity: canDelete ? 'error' : 'warning',
message: t('issues.missing_tag.' + missingTagType + '.message', messageObj),
severity: severity,
message: t('issues.' + messageID + '.message', messageObj),
reference: showReference,
entities: [entity],
fixes: fixes
@@ -102,7 +118,7 @@ export function validationMissingTag() {
.enter()
.append('div')
.attr('class', 'issue-reference')
.text(t('issues.missing_tag.reference'));
.text(t('issues.' + referenceID + '.reference'));
}
};
-64
View File
@@ -1,64 +0,0 @@
import { t } from '../util/locale';
import { operationDelete } from '../operations/index';
import { utilDisplayLabel } from '../util';
import { validationIssue, validationIssueFix } from '../core/validation';
export function validationUnknownRoad() {
var type = 'unknown_road';
var validation = function checkUnknownRoad(entity, context) {
if (entity.type !== 'way' || entity.tags.highway !== 'road') return [];
var fixes = [
new validationIssueFix({
icon: 'iD-icon-search',
title: t('issues.fix.select_road_type.title'),
onClick: function() {
context.ui().sidebar.showPresetList();
}
})
];
if (!operationDelete([entity.id], context).disabled()) {
fixes.push(
new validationIssueFix({
icon: 'iD-operation-delete',
title: t('issues.fix.delete_feature.title'),
onClick: function() {
var id = this.issue.entities[0].id;
var operation = operationDelete([id], context);
if (!operation.disabled()) {
operation();
}
}
})
);
}
return [new validationIssue({
type: type,
severity: 'warning',
message: t('issues.unknown_road.message', {
feature: utilDisplayLabel(entity, context),
}),
reference: showReference,
entities: [entity],
fixes: fixes
})];
function showReference(selection) {
selection.selectAll('.issue-reference')
.data([0])
.enter()
.append('div')
.attr('class', 'issue-reference')
.text(t('issues.unknown_road.reference'));
}
};
validation.type = type;
return validation;
}
-1
View File
@@ -163,7 +163,6 @@
<script src='spec/validations/outdated_tags.js'></script>
<script src='spec/validations/private_data.js'></script>
<script src='spec/validations/tag_suggests_area.js'></script>
<script src='spec/validations/unknown_road.js'></script>
<script>
window.mocha.run();
+16
View File
@@ -101,4 +101,20 @@ describe('iD.validations.missing_tag', function () {
expect(issue.entities[0].id).to.eql('r-1');
});
it('ignores highway with classification', function() {
createWay({ highway: 'primary' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('flags highway=road', function() {
createWay({ highway: 'road' });
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('missing_tag');
expect(issue.entities).to.have.lengthOf(1);
expect(issue.entities[0].id).to.eql('w-1');
});
});
-58
View File
@@ -1,58 +0,0 @@
describe('iD.validations.unknown_road', function () {
var context;
beforeEach(function() {
context = iD.coreContext();
});
function createWay(tags) {
var n1 = iD.osmNode({id: 'n-1', loc: [4,4]});
var n2 = iD.osmNode({id: 'n-2', loc: [4,5]});
var w = iD.osmWay({id: 'w-1', nodes: ['n-1', 'n-2'], tags: tags});
context.perform(
iD.actionAddEntity(n1),
iD.actionAddEntity(n2),
iD.actionAddEntity(w)
);
}
function validate() {
var validator = iD.validationUnknownRoad();
var changes = context.history().changes();
var entities = changes.modified.concat(changes.created);
var issues = [];
entities.forEach(function(entity) {
issues = issues.concat(validator(entity, context));
});
return issues;
}
it('has no errors on init', function() {
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores way with no tags', function() {
createWay({});
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('ignores highway with classification', function() {
createWay({ highway: 'primary' });
var issues = validate();
expect(issues).to.have.lengthOf(0);
});
it('flags highway=road', function() {
createWay({ highway: 'road' });
var issues = validate();
expect(issues).to.have.lengthOf(1);
var issue = issues[0];
expect(issue.type).to.eql('unknown_road');
expect(issue.entities).to.have.lengthOf(1);
expect(issue.entities[0].id).to.eql('w-1');
});
});