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

Last change on this file since 13343 was 13343, checked in by Klumbumbus, 5 months ago

see #15719 - improve/unify validator messages

  • Property svn:eol-style set to native
File size: 11.5 KB
Line 
1/* measurement values and units warnings (ticket #8687) */
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]*( (m|ft))?)|([1-9][0-9]*\'((10|11|[0-9])((\.[0-9]+)?)\")?))$/] {
58  throwWarning: tr("unusual value of {0}: meters is default; point is separator; if units, put space then unit", "{0.key}");
59  assertMatch: "node height=medium";
60  assertMatch: "node height=-5";
61  assertNoMatch: "node height=2 m";
62  assertNoMatch: "node height=5";
63  assertNoMatch: "node height=7.8";
64  assertNoMatch: "node height=20 ft";
65  assertNoMatch: "node height=22'";
66}
67
68*[maxheight][maxheight !~ /^(([1-9][0-9]*(\.[0-9]+)?( (m|ft))?)|([0-9]+\'(([0-9]|10|11)(\.[0-9]*)?\")?)|none|default)$/] {
69  throwWarning: tr("unusual value of {0}: meters is default; point is separator; if units, put space then unit", "{0.key}");
70  assertMatch: "node maxheight=something";
71  assertMatch: "node maxheight=-5";
72  assertMatch: "node maxheight=0";
73  assertNoMatch: "node maxheight=4";
74  assertNoMatch: "node maxheight=3.5";
75  assertNoMatch: "node maxheight=2 m";
76  assertNoMatch: "node maxheight=14 ft";
77  assertNoMatch: "node maxheight=10'";
78  assertNoMatch: "node maxheight=16'3\"";
79}
80
81way[width][width !~ /^(([0-9]+\.?[0-9]*( [a-z]+)?)|([0-9]+\'([0-9]+\.?[0-9]*\")?))$/] {
82  throwWarning: tr("unusual value of {0}: meters is default; point is separator; if units, put space then unit", "{0.key}");
83  assertMatch: "way width=something";
84  assertMatch: "way width=-5";
85  assertNoMatch: "way width=3";
86  assertNoMatch: "way width=0.5";
87  assertNoMatch: "way width=1 m";
88  assertNoMatch: "way width=10 ft";
89  assertNoMatch: "way width=1'";
90  assertNoMatch: "way width=10'5\"";
91}
92
93*[maxwidth][maxwidth !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
94  throwWarning: tr("unusual value of {0}: meters is default; point is separator; if units, put space then unit", "{0.key}");
95  assertMatch: "way maxwidth=something";
96  assertMatch: "way maxwidth=-5";
97  assertNoMatch: "way maxwidth=2";
98  assertNoMatch: "way maxwidth=6'6\"";
99  assertNoMatch: "way maxwidth=2.5";
100  assertNoMatch: "way maxwidth=7 ft";
101}
102*[maxweight][maxweight !~ /^(([0-9]+\.?[0-9]*( (t|kg|lbs))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
103  throwWarning: tr("unusual value of {0}: tonne is default; point is separator; if units, put space then unit", "{0.key}");
104  assertMatch: "way maxweight=something";
105  assertMatch: "way maxweight=-5";
106  assertNoMatch: "way maxweight=2";
107  assertNoMatch: "way maxweight=6'6\"";
108  assertNoMatch: "way maxweight=2.5";
109  assertNoMatch: "way maxweight=7 kg";
110}
111way[maxspeed][maxspeed !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
112way[maxspeed:forward][maxspeed:forward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
113way[maxspeed:backward][maxspeed:backward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/] {
114  throwWarning: tr("unusual value of {0}", "{0.key}");
115  assertMatch: "way maxspeed=something";
116  assertMatch: "way maxspeed=-50";
117  assertMatch: "way maxspeed=0";
118  assertNoMatch: "way maxspeed=50";
119  assertNoMatch: "way maxspeed=30 mph";
120  assertNoMatch: "way maxspeed=RO:urban";
121  assertNoMatch: "way maxspeed=RU:rural";
122  assertNoMatch: "way maxspeed=RU:living_street";
123  assertNoMatch: "way maxspeed=DE:motorway";
124  assertNoMatch: "way maxspeed=signals";
125  assertNoMatch: "way maxspeed=none";
126  assertNoMatch: "way maxspeed=variable";
127}
128
129*[distance][distance !~ /^(([0-9]+\.?[0-9]*( (m|km|mi|nmi))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
130  throwWarning: tr("unusual value of {0}: kilometers is default; point is separator; if units, put space then unit", "{0.key}");
131  assertMatch: "way distance=something";
132  assertMatch: "way distance=-5";
133  assertNoMatch: "way distance=2";
134  assertNoMatch: "way distance=2.5";
135  assertNoMatch: "way distance=7 mi";
136}
137
138way[voltage][voltage =~ /(.*[A-Za-z].*)|.*,.*|.*( ).*/] {
139  throwWarning: tr("voltage should be in volts with no units/delimiter/spaces");
140  assertMatch: "way voltage=medium";
141  assertNoMatch: "way voltage=15000";
142}
143
144/* some users are using frequency for other purposes (not electromagnetic)
145   with the values 'perennial' and 'intermittent'; the vast majority are 0, 16.7, 50 and 60 */
146way[frequency][frequency !~ /^(0|[1-9][0-9]*(\.[0-9]+)?)( (kHz|MHz|GHz|THz))?$/] {
147  throwWarning: tr("unusual value of {0}", "{0.key}");
148  assertMatch: "way frequency=something";
149  assertNoMatch: "way frequency=0"; /* DC */
150  assertNoMatch: "way frequency=16.7";
151  assertNoMatch: "way frequency=50";
152  assertNoMatch: "way frequency=680 kHz";
153  assertNoMatch: "way frequency=123.5 MHz";
154}
155
156way[gauge][gauge !~ /^([1-9][0-9]{1,3}(;[1-9][0-9]{1,3})*|broad|standard|narrow)$/] {
157  throwWarning: tr("unusual value of {0}", "{0.key}");
158  assertMatch: "way gauge=something";
159  assertNoMatch: "way gauge=1435";
160  assertNoMatch: "way gauge=1000;1435";
161  assertNoMatch: "way gauge=standard";
162  assertNoMatch: "way gauge=narrow";
163}
164
165/* the numbers for percentage and degrees include could probably be bracketed a bit more precisely */
166way[incline][incline !~ /^(up|down|-?([0-9]+?(\.[1-9]%)?|100)[%°]?)$/] {
167  throwWarning: tr("unusual value of {0}", "{0.key}");
168  suggestAlternative: "x%";
169  suggestAlternative: "x°";
170  suggestAlternative: "up";
171  suggestAlternative: "down";
172  assertMatch: "way incline=extreme";
173  assertNoMatch: "way incline=up";
174  assertNoMatch: "way incline=down";
175  assertNoMatch: "way incline=10%";
176  assertNoMatch: "way incline=-5%";
177  assertNoMatch: "way incline=10°";
178}
179
180/* see ticket #9631 */
181*[population][population !~ /^[0-9]+$/ ] {
182  throwWarning: tr("{0} must be a numeric value", "{0.key}");
183}
184
185/* must be an integer positive number only and not 0, see #10837 (lanes), #11055 (screen) */
186way[lanes][lanes !~ /^[1-9]([0-9]*)$/][highway],
187way["lanes:backward"]["lanes:backward" !~ /^[1-9]([0-9]*)$/][highway],
188way["lanes:forward"]["lanes:forward" !~ /^[1-9]([0-9]*)$/][highway],
189*[screen][screen !~ /^[1-9]([0-9]*)$/][amenity=cinema] {
190  throwError: tr("{0} must be a positive integer number", "{0.key}");
191  assertMatch: "way highway=residential lanes=-1";
192  assertMatch: "way highway=residential lanes=5.5";
193  assertMatch: "way highway=residential lanes=1;2";
194  assertMatch: "way highway=residential lanes:forward=-1";
195  assertMatch: "way highway=residential lanes:backward=-1";
196  assertNoMatch: "way highway=residential lanes=1";
197  assertMatch: "node amenity=cinema screen=led";
198  assertNoMatch: "node amenity=cinema screen=8";
199}
200*[admin_level][admin_level !~ /^(1|2|3|4|5|6|7|8|9|10|11|12)$/] {
201  throwWarning: tr("unusual value of {0}", "{0.key}");
202  assertMatch: "node admin_level=0";
203  assertMatch: "node admin_level=-1";
204  assertMatch: "node admin_level=13";
205  assertNoMatch: "node admin_level=5";
206}
207
208/* #14989 */
209*[direction][direction<0],
210*[direction][direction>=360] {
211  throwWarning: tr("unusual value of {0}", "{0.key}");
212  assertMatch: "node direction=-10";
213  assertMatch: "node direction=360";
214  assertNoMatch: "node direction=0";
215}
216*[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))*$/] {
217  throwWarning: tr("unusual value of {0}", "{0.key}");
218  assertMatch: "node direction=north-down";
219  assertMatch: "node direction=rome";
220  assertMatch: "node direction=C";
221  assertMatch: "node direction=NNNE";
222  assertMatch: "node direction=1360";
223  assertNoMatch: "node direction=NE-S"; /* ranges are used at tourism=viewpoint*/
224  assertMatch: "node direction=north-south"; /* ranges only in numbers or short NESW form */
225  assertMatch: "node direction=north-east"; /* if range use N-E, if single direcion use NE */
226  assertNoMatch: "node direction=0-360"; /* complete panorama view */
227  assertNoMatch: "node direction=45-100;190-250;300-360";
228  assertMatch: "node direction=45-100;190-250;300";
229  assertNoMatch: "node direction=up"; 
230  assertNoMatch: "node direction=down"; /* up/down are replaced by incline tag, has separate warning */
231  assertNoMatch: "node direction=0";
232  assertNoMatch: "node direction=45";
233  assertNoMatch: "node direction=360";
234  assertNoMatch: "node direction=N";
235  assertNoMatch: "node direction=NNE";
236  assertNoMatch: "node direction=west";
237  assertNoMatch: "node direction=forward";
238  assertNoMatch: "node direction=anti-clockwise";
239  assertNoMatch: "node direction=anticlockwise"; /* both spellings are in use and even wiki uses both */
240}
241
242/* #14786 (should be safe to just remove the meters unit from the value) */
243*[ele][ele =~ /^-?[0-9]+(\.[0-9]+)? ?m$/] {
244  throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
245  fixAdd: concat("ele=", trim(replace(tag("ele"), "m", "")));
246  set .ele_is_fixable;
247  assertMatch: "node ele=12m";
248  assertMatch: "node ele=12 m";
249  assertNoMatch: "node ele=12km";
250  assertMatch: "node ele=12.1m";
251  assertMatch: "node ele=-12.1 m";
252  assertNoMatch: "node ele=12";
253  assertNoMatch: "node ele=high";
254}
255*[ele][ele !~ /^-?[0-9]+(\.[0-9]+)?$/]!.ele_is_fixable{
256  throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
257  assertNoMatch: "node ele=12m";
258  assertNoMatch: "node ele=12 m";
259  assertMatch: "node ele=12km";
260  assertNoMatch: "node ele=12.1m";
261  assertNoMatch: "node ele=-12.1 m";
262  assertNoMatch: "node ele=12";
263  assertMatch: "node ele=high";
264}
Note: See TracBrowser for help on using the repository browser.