source: josm/trunk/data/validator/numeric.mapcss@ 14113

Last change on this file since 14113 was 13357, checked in by Klumbumbus, 7 years ago

fix #15719 - restrict comma autofix to max. 2 decimal places to avoid false fixes of thousands separators

  • Property svn:eol-style set to native
File size: 15.2 KB
Line 
1/* measurement values and units warnings (tickets #8687, #15719) */
2
3*[/^[0-9]+$/] {
4 throwWarning: tr("numerical key");
5 assertMatch: "way 123=foo";
6 assertNoMatch: "way ref.1=foo";
7}
8
9*[layer =~ /^\+\d/] {
10 throwWarning: tr("{0} value with + sign", "{0.key}");
11 fixAdd: concat("layer=", replace(tag("layer"), "+", ""));
12 assertMatch: "node layer=+1";
13 assertNoMatch: "node layer=1";
14 assertNoMatch: "node layer=-1";
15 assertNoMatch: "node layer=+foo";
16}
17
18*[layer][layer !~ /^0$|^(-|\+)?[1-5]$/] {
19 throwWarning: tr("{0} should be an integer value between -5 and 5", "{0.key}");
20 assertMatch: "node layer=-50";
21 assertMatch: "node layer=6";
22 assertMatch: "node layer=+10";
23 assertMatch: "node layer=0.5";
24 assertMatch: "node layer=0;1";
25 assertNoMatch: "node layer=-5";
26 assertNoMatch: "node layer=0";
27 assertNoMatch: "node layer=2";
28 assertNoMatch: "node layer=+5"; /* this is an invalid value, but this case is already covered by the previous rule */
29}
30
31*[building:levels][building:levels !~ /^(([0-9]|[1-9][0-9]*)(\.5)?)$/],
32*[level][level !~ /^((((-*[1-9]|[0-9])|-*[1-9][0-9]*)(\.5)?)|-0\.5)(;((((-*[1-9]|[0-9])|-*[1-9][0-9]*)(\.5)?)|-0\.5))*$/] { /* all numbers from -∞ to ∞ in 0.5 steps, optional multiple values seperated by a ; */
33 throwWarning: tr("{0} should have numbers only with optional .5 increments", "{0.key}");
34 assertMatch: "node level=one";
35 assertMatch: "node level=01";
36 assertMatch: "node level=-03";
37 assertMatch: "node level=-01.5";
38 assertMatch: "node level=2.3";
39 assertMatch: "node level=-0";
40 assertNoMatch: "node level=0";
41 assertNoMatch: "node level=1";
42 assertNoMatch: "node level=-1";
43 assertNoMatch: "node level=-0.5";
44 assertNoMatch: "node level=1.5";
45 assertNoMatch: "node level=12";
46 assertNoMatch: "node level=0;1";
47 assertNoMatch: "node level=1;1.5";
48 assertNoMatch: "node level=1;0.5";
49 assertNoMatch: "node level=0;-0.5";
50 assertNoMatch: "node level=-0.5;0";
51 assertNoMatch: "node level=-1;-0.5";
52 assertNoMatch: "node building:levels=1.5";
53 assertMatch: "node building:levels=-1";
54 assertNoMatch: "node building:levels=0"; /* valid because there can be building:levels:underground > 0 or roof:levels > 0 */
55}
56
57*[height][height =~ /^[0-9]+,[0-9][0-9]?( (m|ft))?$/] {
58 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
59 fixAdd: concat("height=", replace(tag("height"), ",", "."));
60 set height_separator_autofix;
61 assertMatch: "node height=5,5";
62 assertMatch: "node height=12,00";
63 assertMatch: "node height=12,5 ft";
64 assertNoMatch: "node height=12,000";
65 assertNoMatch: "node height=3,50,5";
66 assertNoMatch: "node height=3.5";
67 assertNoMatch: "node height=4";
68}
69*[height][height !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([1-9][0-9]*\'((10|11|[0-9])((\.[0-9]+)?)\")?))$/]!.height_separator_autofix {
70 throwWarning: tr("unusual value of {0}: meters is default; point is decimal separator; if units, put space then unit", "{0.key}");
71 assertMatch: "node height=medium";
72 assertMatch: "node height=-5";
73 assertNoMatch: "node height=2 m";
74 assertNoMatch: "node height=5";
75 assertNoMatch: "node height=7.8";
76 assertNoMatch: "node height=20 ft";
77 assertNoMatch: "node height=22'";
78}
79
80*[maxheight][maxheight =~ /^[0-9]+,[0-9][0-9]?( (m|ft))?$/] {
81 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
82 fixAdd: concat("maxheight=", replace(tag("maxheight"), ",", "."));
83 set maxheight_separator_autofix;
84 assertMatch: "node maxheight=5,5";
85 assertMatch: "node maxheight=12,00";
86 assertMatch: "node maxheight=12,5 ft";
87 assertNoMatch: "node maxheight=12,000";
88 assertNoMatch: "node maxheight=3,50,5";
89 assertNoMatch: "node maxheight=3.5";
90 assertNoMatch: "node maxheight=4";
91}
92*[maxheight][maxheight !~ /^(([1-9][0-9]*(\.[0-9]+)?( (m|ft))?)|([0-9]+\'(([0-9]|10|11)(\.[0-9]*)?\")?)|none|default)$/]!.maxheight_separator_autofix {
93 throwWarning: tr("unusual value of {0}: meters is default; point is decimal separator; if units, put space then unit", "{0.key}");
94 assertMatch: "node maxheight=something";
95 assertMatch: "node maxheight=-5";
96 assertMatch: "node maxheight=0";
97 assertNoMatch: "node maxheight=4";
98 assertNoMatch: "node maxheight=3.5";
99 assertNoMatch: "node maxheight=2 m";
100 assertNoMatch: "node maxheight=14 ft";
101 assertNoMatch: "node maxheight=10'";
102 assertNoMatch: "node maxheight=16'3\"";
103}
104
105*[width][width =~ /^[0-9]+,[0-9][0-9]?( (m|ft))?$/] {
106 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
107 fixAdd: concat("width=", replace(tag("width"), ",", "."));
108 set width_separator_autofix;
109 assertMatch: "node width=5,5";
110 assertMatch: "node width=12,00";
111 assertNoMatch: "node width=12,000";
112 assertNoMatch: "node width=3,50,5";
113 assertNoMatch: "node width=3.5";
114 assertNoMatch: "node width=4";
115}
116*[width][width !~ /^(([0-9]+\.?[0-9]*( [a-z]+)?)|([0-9]+\'([0-9]+\.?[0-9]*\")?))$/]!.width_separator_autofix {
117 throwWarning: tr("unusual value of {0}: meters is default; point is decimal separator; if units, put space then unit", "{0.key}");
118 assertMatch: "way width=something";
119 assertMatch: "way width=-5";
120 assertNoMatch: "way width=3";
121 assertNoMatch: "way width=0.5";
122 assertNoMatch: "way width=1 m";
123 assertNoMatch: "way width=10 ft";
124 assertNoMatch: "way width=1'";
125 assertNoMatch: "way width=10'5\"";
126}
127
128*[maxwidth][maxwidth =~ /^[0-9]+,[0-9][0-9]?( (m|ft))?$/] {
129 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
130 fixAdd: concat("maxwidth=", replace(tag("maxwidth"), ",", "."));
131 set maxwidth_separator_autofix;
132 assertMatch: "node maxwidth=5,5";
133 assertMatch: "node maxwidth=12,00";
134 assertNoMatch: "node maxwidth=12,000";
135 assertNoMatch: "node maxwidth=3,50,5";
136 assertNoMatch: "node maxwidth=3.5";
137 assertNoMatch: "node maxwidth=4";
138}
139*[maxwidth][maxwidth !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/]!.maxwidth_separator_autofix {
140 throwWarning: tr("unusual value of {0}: meters is default; point is decimal separator; if units, put space then unit", "{0.key}");
141 assertMatch: "way maxwidth=something";
142 assertMatch: "way maxwidth=-5";
143 assertNoMatch: "way maxwidth=2";
144 assertNoMatch: "way maxwidth=6'6\"";
145 assertNoMatch: "way maxwidth=2.5";
146 assertNoMatch: "way maxwidth=7 ft";
147}
148
149*[maxweight][maxweight =~ /^[0-9]+,[0-9][0-9]?( (t|kg|lbs))?$/] {
150 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
151 fixAdd: concat("maxweight=", replace(tag("maxweight"), ",", "."));
152 set maxweight_separator_autofix;
153 assertMatch: "node maxweight=5,5";
154 assertMatch: "node maxweight=12,00";
155 assertNoMatch: "node maxweight=12,000";
156 assertNoMatch: "node maxweight=3,50,5";
157 assertNoMatch: "node maxweight=3.5";
158 assertNoMatch: "node maxweight=4";
159}
160*[maxweight][maxweight !~ /^(([0-9]+\.?[0-9]*( (t|kg|lbs))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/]!.maxweight_separator_autofix {
161 throwWarning: tr("unusual value of {0}: tonne is default; point is decimal separator; if units, put space then unit", "{0.key}");
162 assertMatch: "way maxweight=something";
163 assertMatch: "way maxweight=-5";
164 assertNoMatch: "way maxweight=2";
165 assertNoMatch: "way maxweight=6'6\"";
166 assertNoMatch: "way maxweight=2.5";
167 assertNoMatch: "way maxweight=7 kg";
168}
169
170way[maxspeed][maxspeed !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
171way[maxspeed:forward][maxspeed:forward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
172way[maxspeed:backward][maxspeed:backward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/] {
173 throwWarning: tr("unusual value of {0}", "{0.key}");
174 assertMatch: "way maxspeed=something";
175 assertMatch: "way maxspeed=-50";
176 assertMatch: "way maxspeed=0";
177 assertNoMatch: "way maxspeed=50";
178 assertNoMatch: "way maxspeed=30 mph";
179 assertNoMatch: "way maxspeed=RO:urban";
180 assertNoMatch: "way maxspeed=RU:rural";
181 assertNoMatch: "way maxspeed=RU:living_street";
182 assertNoMatch: "way maxspeed=DE:motorway";
183 assertNoMatch: "way maxspeed=signals";
184 assertNoMatch: "way maxspeed=none";
185 assertNoMatch: "way maxspeed=variable";
186}
187
188*[distance][distance =~ /^[0-9]+,[0-9][0-9]?( (m|km|mi|nmi))?$/] {
189 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
190 fixAdd: concat("distance=", replace(tag("distance"), ",", "."));
191 set distance_separator_autofix;
192 assertMatch: "node distance=5,5";
193 assertMatch: "node distance=12,00";
194 assertNoMatch: "node distance=12,000";
195 assertNoMatch: "node distance=3,50,5";
196 assertNoMatch: "node distance=3.5";
197 assertNoMatch: "node distance=4";
198}
199*[distance][distance !~ /^(([0-9]+\.?[0-9]*( (m|km|mi|nmi))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/]!.distance_separator_autofix {
200 throwWarning: tr("unusual value of {0}: kilometers is default; point is decimal separator; if units, put space then unit", "{0.key}");
201 assertMatch: "way distance=something";
202 assertMatch: "way distance=-5";
203 assertNoMatch: "way distance=2";
204 assertNoMatch: "way distance=2.5";
205 assertNoMatch: "way distance=7 mi";
206}
207
208way[voltage][voltage =~ /(.*[A-Za-z].*)|.*,.*|.*( ).*/] {
209 throwWarning: tr("voltage should be in volts with no units/delimiter/spaces");
210 assertMatch: "way voltage=medium";
211 assertNoMatch: "way voltage=15000";
212}
213
214/* some users are using frequency for other purposes (not electromagnetic)
215 with the values 'perennial' and 'intermittent'; the vast majority are 0, 16.7, 50 and 60 */
216way[frequency][frequency !~ /^(0|[1-9][0-9]*(\.[0-9]+)?)( (kHz|MHz|GHz|THz))?$/] {
217 throwWarning: tr("unusual value of {0}", "{0.key}");
218 assertMatch: "way frequency=something";
219 assertNoMatch: "way frequency=0"; /* DC */
220 assertNoMatch: "way frequency=16.7";
221 assertNoMatch: "way frequency=50";
222 assertNoMatch: "way frequency=680 kHz";
223 assertNoMatch: "way frequency=123.5 MHz";
224}
225
226way[gauge][gauge !~ /^([1-9][0-9]{1,3}(;[1-9][0-9]{1,3})*|broad|standard|narrow)$/] {
227 throwWarning: tr("unusual value of {0}", "{0.key}");
228 assertMatch: "way gauge=something";
229 assertNoMatch: "way gauge=1435";
230 assertNoMatch: "way gauge=1000;1435";
231 assertNoMatch: "way gauge=standard";
232 assertNoMatch: "way gauge=narrow";
233}
234
235/* the numbers for percentage and degrees include could probably be bracketed a bit more precisely */
236way[incline][incline !~ /^(up|down|-?([0-9]+?(\.[1-9]%)?|100)[%°]?)$/] {
237 throwWarning: tr("unusual value of {0}", "{0.key}");
238 suggestAlternative: "x%";
239 suggestAlternative: "x°";
240 suggestAlternative: "up";
241 suggestAlternative: "down";
242 assertMatch: "way incline=extreme";
243 assertNoMatch: "way incline=up";
244 assertNoMatch: "way incline=down";
245 assertNoMatch: "way incline=10%";
246 assertNoMatch: "way incline=-5%";
247 assertNoMatch: "way incline=10°";
248}
249
250/* see ticket #9631 */
251*[population][population !~ /^[0-9]+$/ ] {
252 throwWarning: tr("{0} must be a numeric value", "{0.key}");
253}
254
255/* must be an integer positive number only and not 0, see #10837 (lanes), #11055 (screen) */
256way[lanes][lanes !~ /^[1-9]([0-9]*)$/][highway],
257way["lanes:backward"]["lanes:backward" !~ /^[1-9]([0-9]*)$/][highway],
258way["lanes:forward"]["lanes:forward" !~ /^[1-9]([0-9]*)$/][highway],
259*[screen][screen !~ /^[1-9]([0-9]*)$/][amenity=cinema] {
260 throwError: tr("{0} must be a positive integer number", "{0.key}");
261 assertMatch: "way highway=residential lanes=-1";
262 assertMatch: "way highway=residential lanes=5.5";
263 assertMatch: "way highway=residential lanes=1;2";
264 assertMatch: "way highway=residential lanes:forward=-1";
265 assertMatch: "way highway=residential lanes:backward=-1";
266 assertNoMatch: "way highway=residential lanes=1";
267 assertMatch: "node amenity=cinema screen=led";
268 assertNoMatch: "node amenity=cinema screen=8";
269}
270*[admin_level][admin_level !~ /^(1|2|3|4|5|6|7|8|9|10|11|12)$/] {
271 throwWarning: tr("unusual value of {0}", "{0.key}");
272 assertMatch: "node admin_level=0";
273 assertMatch: "node admin_level=-1";
274 assertMatch: "node admin_level=13";
275 assertNoMatch: "node admin_level=5";
276}
277
278/* #14989 */
279*[direction][direction<0],
280*[direction][direction>=360] {
281 throwWarning: tr("unusual value of {0}", "{0.key}");
282 assertMatch: "node direction=-10";
283 assertMatch: "node direction=360";
284 assertNoMatch: "node direction=0";
285}
286*[direction][direction !~ /^([0-9][0-9]?[0-9]?|north|east|south|west|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW|forward|backward|both|clockwise|anti-clockwise|anticlockwise|up|down)(-([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW))?(;([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW)-([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW))*$/] {
287 throwWarning: tr("unusual value of {0}", "{0.key}");
288 assertMatch: "node direction=north-down";
289 assertMatch: "node direction=rome";
290 assertMatch: "node direction=C";
291 assertMatch: "node direction=NNNE";
292 assertMatch: "node direction=1360";
293 assertNoMatch: "node direction=NE-S"; /* ranges are used at tourism=viewpoint*/
294 assertMatch: "node direction=north-south"; /* ranges only in numbers or short NESW form */
295 assertMatch: "node direction=north-east"; /* if range use N-E, if single direcion use NE */
296 assertNoMatch: "node direction=0-360"; /* complete panorama view */
297 assertNoMatch: "node direction=45-100;190-250;300-360";
298 assertMatch: "node direction=45-100;190-250;300";
299 assertNoMatch: "node direction=up";
300 assertNoMatch: "node direction=down"; /* up/down are replaced by incline tag, has separate warning */
301 assertNoMatch: "node direction=0";
302 assertNoMatch: "node direction=45";
303 assertNoMatch: "node direction=360";
304 assertNoMatch: "node direction=N";
305 assertNoMatch: "node direction=NNE";
306 assertNoMatch: "node direction=west";
307 assertNoMatch: "node direction=forward";
308 assertNoMatch: "node direction=anti-clockwise";
309 assertNoMatch: "node direction=anticlockwise"; /* both spellings are in use and even wiki uses both */
310}
311
312/* #14786 (should be safe to just remove the meters unit from the value) */
313*[ele][ele =~ /^-?[0-9]+(\.[0-9]+)? ?m$/] {
314 throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
315 fixAdd: concat("ele=", trim(replace(tag("ele"), "m", "")));
316 set ele_meter_remove_autofix;
317 assertMatch: "node ele=12m";
318 assertMatch: "node ele=12 m";
319 assertNoMatch: "node ele=12km";
320 assertMatch: "node ele=12.1m";
321 assertMatch: "node ele=-12.1 m";
322 assertNoMatch: "node ele=12";
323 assertNoMatch: "node ele=high";
324}
325*[ele][ele =~ /^[0-9]+,[0-9][0-9]?$/] {
326 throwWarning: tr("unusual value of {0}: use . instead of , as decimal separator", "{0.key}");
327 fixAdd: concat("ele=", replace(tag("ele"), ",", "."));
328 set ele_separator_autofix;
329 assertMatch: "node ele=5,5";
330 assertMatch: "node ele=12,00";
331 assertNoMatch: "node ele=8,848"; /* wrongly used thousands separator */
332 assertNoMatch: "node ele=3,50,5";
333 assertNoMatch: "node ele=3.5";
334 assertNoMatch: "node ele=4";
335}
336*[ele][ele !~ /^-?[0-9]+(\.[0-9]+)?$/]!.ele_meter_remove_autofix!.ele_separator_autofix{
337 throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
338 assertNoMatch: "node ele=12m";
339 assertNoMatch: "node ele=12 m";
340 assertMatch: "node ele=12km";
341 assertNoMatch: "node ele=12.1m";
342 assertNoMatch: "node ele=-12.1 m";
343 assertNoMatch: "node ele=12";
344 assertMatch: "node ele=high";
345}
Note: See TracBrowser for help on using the repository browser.