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

Last change on this file since 13345 was 13345, checked in by Klumbumbus, 4 months ago

see #15719 - provide autofix for replacing single comma by point for several numeric tags

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