way[highway=~/^(motorway|trunk|primary|secondary|tertiary)$/] {
  set major_road;
}
way[highway=~/^.*_link$/] {
  set link_road;
}
way[highway=~/^(unclassified|residential|living_street|service)$/] {
  set minor_road;
}

way[highway][name =~ /(?i).* (Ave|Blvd|Br|Brg|Cct|Cir|Cl|Cr|Crct|Cres|Crt|Ct|Dr|Drv|Esp|Espl|Hwy|Ln|Mw|Mwy|Pky|Pkwy|Pl|Rd|Qy|Qys|Sq|St|Str|Ter|Tce|Tr|Wy)[.]?$/] {
  throwWarning: tr("abbreviated street name");
  assertMatch: "way highway=unclassified name=\"Foo Ave\"";
  assertMatch: "way highway=unclassified name=\"Foo Ave.\"";
  assertMatch: "way highway=unclassified name=\"Bou Blvd.\"";
  assertMatch: "way highway=unclassified name=\"Bou blvd.\"";
}

node[highway =~ /motorway|trunk|primary|secondary|tertiary|unclassified|residential|service|living_street|pedestrian|track|path|footway|cycleway|bus_guideway|bridleway/][highway!=motorway_junction][highway!=services] {
  throwWarning: tr("wrong highway tag on a node");
  assertMatch: "node highway=primary";
  assertMatch: "node highway=primary_link";
  assertNoMatch: "node highway=traffic_calming";
  assertNoMatch: "node highway=bus_stop";
  assertNoMatch: "node highway=crossing";
  assertNoMatch: "node highway=emergency_access_point";
  assertNoMatch: "node highway=give_way";
  assertNoMatch: "node highway=mini_roundabout";
  assertNoMatch: "node highway=motorway_junction";
  assertNoMatch: "node highway=passing_place";
  assertNoMatch: "node highway=rest_area";
  assertNoMatch: "node highway=speed_camera";
  assertNoMatch: "node highway=street_lamp";
  assertNoMatch: "node highway=services";
  assertNoMatch: "node highway=stop";
  assertNoMatch: "node highway=traffic_signals";
  assertNoMatch: "node highway=turning_circle";
}

way[highway=crossing],
way[railway=crossing],
way[railway=level_crossing] {
  throwWarning: tr("wrong crossing tag on a way");
  assertMatch: "way highway=crossing";
  assertNoMatch: "node highway=crossing";
}

way[highway=unclassified][!name][noname!=yes] {
  throwOther: tr("Unnamed unclassified highway");
  assertMatch: "way highway=unclassified";
  assertNoMatch: "way highway=unclassified noname=yes";
  assertNoMatch: "way highway=unclassified name=Foo";
}

way.major_road[!ref][!destination:ref][noref!=yes][junction!=roundabout] {
  throwOther: tr("highway without a reference");
  group: tr("missing tag");
  assertMatch: "way highway=primary";
  assertNoMatch: "way highway=primary ref=123";
  assertNoMatch: "way highway=primary destination:ref=123";
  assertNoMatch: "way highway=primary noref=yes";
}

way[highway=road] {
  throwWarning: tr("Unspecific highway type");
  assertMatch: "way highway=road";
  assertNoMatch: "way highway=residential";
}

way[highway=footway][maxspeed],
way[highway=steps][maxspeed],
way[highway=cycleway][bicycle=no],
way[highway=footway][foot=no],
way[highway=cycleway][cycleway=lane] {
  throwWarning: tr("{0} used with {1}", "{0.value}", "{1.tag}");
  assertNoMatch: "way highway=cycleway bicycle=yes";
  assertNoMatch: "way highway=cycleway";
  assertNoMatch: "way highway=footway foot=yes";
  assertNoMatch: "way highway=footway";
  assertMatch: "way highway=cycleway cycleway=lane";
  assertNoMatch: "way highway=cycleway";
  assertNoMatch: "way highway=residential cycleway=lane";
  assertMatch: "way highway=footway maxspeed=20";
  assertNoMatch: "way highway=residential maxspeed=20";
  assertNoMatch: "way highway=footway";
}

/* footway, see #10851, #10976, #15439 */
way[footway=left][/^footway:/],
way[footway=right][/^footway:/],
way[footway=both][/^footway:/],
way[footway=no][/^footway:/] {
  throwWarning: tr("{0} is deprecated, use {1} instead. Also check similar tags like {2}", "{0.tag}", "sidewalk", "{1.key}");
  group: tr("deprecated tagging");
  set not_fixable_footway;
  assertMatch: "way footway=both footway:surface=asphalt";
}
way[footway=none][/footway:/] {
  throwWarning: tr("{0} is deprecated, use {1} instead. Also check similar tags like {2}", "{0.tag}", "sidewalk=no", "{1.key}");
  group: tr("deprecated tagging");
  set not_fixable_footway;
}
way[footway=left]!.not_fixable_footway,
way[footway=right]!.not_fixable_footway,
way[footway=both]!.not_fixable_footway,
way[footway=no]!.not_fixable_footway {
  throwWarning: tr("{0} is deprecated", "{0.tag}");
  suggestAlternative: "sidewalk";
  group: tr("deprecated tagging");
  fixChangeKey: "footway => sidewalk";
  set fixable_footway;
}
way[footway=none]!.not_fixable_footway {
  throwWarning: tr("{0} is deprecated", "{0.tag}");
  suggestAlternative: "sidewalk=no";
  group: tr("deprecated tagging");
  fixRemove: "footway";
  fixAdd: "sidewalk=no";
  set fixable_footway;
}
way[footway][footway!=sidewalk][footway!=crossing]!.fixable_footway!.not_fixable_footway { /* do not trigger this rule if already one of the 4 previous rules applied */
  throwWarning: tr("Value of ''{0}'' should either be ''{1}'' or ''{2}''. For sidewalks use ''{3}'' instead.", "{0.key}", "{1.value}", "{2.value}", "sidewalk=left|right|both|no");
  assertNoMatch: "way footway=left";
  assertNoMatch: "way footway=none";
  assertNoMatch: "way footway=left footway:left:surface=asphalt";
  assertMatch: "way footway=bar";
}

/* #11270, #9297, #15439, #16424 */
way[railway =~ /^(light_rail|miniature|narrow_gauge|preserved|rail)$/][!highway] > node { set .is_in_railway }
way[highway =~ /^(bridleway|cycleway|footway|path|steps)$/] > node { set .is_in_minor_road }
way[highway =~ /^(bus_guideway|living_street|motorway|motorway_link|pedestrian|primary|primary_link|raceway|residential|road|secondary|secondary_link|service|tertiary|tertiary_link|track|trunk|trunk_link|unclassified)$/] > node { set .is_in_major_road }
node[railway!=crossing][crossing!=no].is_in_railway.is_in_minor_road!.is_in_major_road {
  throwWarning: tr("pedestrian railway crossing without {0}", "{0.tag}");
  group: tr("missing tag");
  fixAdd: "railway=crossing";
}
node[railway!=level_crossing].is_in_railway.is_in_major_road!.is_in_minor_road {
  throwWarning: tr("railway crossing without {0}", "{0.tag}");
  group: tr("missing tag");
  fixAdd: "railway=level_crossing";
}