Files
iD/modules/validations/generic_name.js
Quincy Morgan 957eb28242 Don't run other validators if feature is missing tags
Don't run disconnected highway check if there is an almost junction issue already
Only run way validators on ways
2019-01-30 17:59:23 -05:00

82 lines
2.5 KiB
JavaScript

import _clone from 'lodash-es/clone';
import { t } from '../util/locale';
import {
utilPreset
} from '../util';
import {
ValidationIssueType,
ValidationIssueSeverity,
validationIssue,
validationIssueFix
} from './validation_issue';
import {
actionChangeTags
} from '../actions';
import { discardNames } from '../../node_modules/name-suggestion-index/config/filters.json';
export function validationGenericName(context) {
function isGenericName(entity) {
var name = entity.tags.name;
if (!name) return false;
var i, re;
// test if the name is just the tag value (e.g. "park")
var keys = ['amenity', 'leisure', 'shop', 'man_made', 'tourism'];
for (i = 0; i < keys.length; i++) {
var val = entity.tags[keys[i]];
if (val && val.replace(/\_/g, ' ').toLowerCase() === name.toLowerCase()) {
return name;
}
}
// test if the name is a generic name (e.g. "pizzaria")
for (i = 0; i < discardNames.length; i++) {
re = new RegExp(discardNames[i], 'i');
if (re.test(name)) {
return name;
}
}
return false;
}
var validation = function(entity) {
var issues = [];
var generic = isGenericName(entity);
if (generic) {
var preset = utilPreset(entity, context);
issues.push(new validationIssue({
type: ValidationIssueType.generic_name,
severity: ValidationIssueSeverity.warning,
message: t('issues.generic_name.message', {feature: preset.name(), name: generic}),
tooltip: t('issues.generic_name.tip'),
entities: [entity],
fixes: [
new validationIssueFix({
title: t('issues.fix.remove_generic_name.title'),
onClick: function() {
var entity = this.issue.entities[0];
var tags = _clone(entity.tags);
delete tags.name;
context.perform(
actionChangeTags(entity.id, tags),
t('issues.fix.remove_generic_name.undo_redo')
);
}
})
]
}));
}
return issues;
};
validation.type = ValidationIssueType.generic_name;
return validation;
}