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

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

fix #15439 - fine tune some validator rules (patch by nyurik)

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