/* Rules partially derived from Taginfo statistics - see ticket #5017
 * Taginfo query: select keypairs.key1, keypairs.key2, keypairs.count_all, keys.count_all, cast(keypairs.count_all as real)/keys.count_all as from_fraction_all from keys, keypairs where key1='waterway' and keys.key=keypairs.key2 and (key1<>'highway' or keypairs.count_all>12000) and (key1<>'railway' or keypairs.count_all>3000) and (key1<>'waterway' or keypairs.count_all>800) and key2 not like '%:%' and from_fraction_all>0.97 and 1 union select keypairs.key2, keypairs.key1, keypairs.count_all, keys.count_all, cast(keypairs.count_all as real)/keys.count_all as from_fraction_all from keys, keypairs where key2='waterway' and keys.key=keypairs.key1 and (key2<>'highway' or keypairs.count_all>12000) and (key2<>'railway' or keypairs.count_all>3000) and (key2<>'waterway' or keypairs.count_all>800) and key1 not like '%:%' and from_fraction_all>0.97 and 1 order by keypairs.count_all desc limit 1000;
 */

/* {0.key} without {1.key} (warning level) */
way[junction                   ][!highway][junction!=yes],
*[lanes                        ][!highway],
*[lcn                          ][!highway],
*[living_street                ][!highway],
*[maintenance                  ][!highway],
*[median                       ][!highway],
*[motorroad                    ][!highway],
*[ntd_id                       ][!highway],
*[sac_scale                    ][!highway],
*[sidewalk                     ][!highway],
*[step_count                   ][!highway],
*[tracktype                    ][!highway],
*[trail_visibility             ][!highway],
*[trolley_wire                 ][!highway],
*[zip_left                     ][!highway],
*[zip_right                    ][!highway],
*[detail                       ][!railway][route!=railway],
*[eddy_current_brake           ][!railway][route!=railway],
*[electrified                  ][!railway][route!=railway],
*[etcs                         ][!railway][route!=railway],
*[gauge                        ][!railway][route!=railway],
*[grade_of_track               ][!railway][route!=railway],
*[kursbuchstrecke              ][!railway][route!=railway],
*[lzb                          ][!railway][route!=railway],
*[old_railway_operator         ][!railway][route!=railway],
*[operating_procedure          ][!railway][route!=railway],
*[pzb                          ][!railway][route!=railway],
*[radio                        ][!railway][route!=railway],
*[structure_gauge              ][!railway][route!=railway],
*[tilting_technology           ][!railway][route!=railway],
*[track_class                  ][!railway][route!=railway],
*[tracks                       ][!railway][route!=railway],
*[traffic_mode                 ][!railway][route!=railway],
*[usage                        ][!railway][route!=railway],
*[workrules                    ][!railway][route!=railway],
*[stream                       ][!waterway],
*[length_unit                  ][!waterway],
*[llid                         ][!waterway],
*[canal                        ][!waterway],
*[have_riverbank               ][!waterway],
*[border_type                  ][!boundary],
*[bridge:structure             ][!bridge],
*[piste:difficulty             ][!piste:type],
*[source:date                  ][!source],
*[source:name                  ][!name],
*[source:maxspeed:forward      ][!maxspeed:forward],
*[source:maxspeed:backward     ][!maxspeed:backward],
*[source:maxspeed:forward      ][!source:maxspeed:backward],
*[source:maxspeed:backward     ][!source:maxspeed:forward],
*[source:building              ][!building],
*[source:ref                   ][!ref],
*[source:population            ][!population],
*[source:postal_code           ][!postal_code],
*[source:ele                   ][!ele],
*[source:ref:INSEE             ][!ref:INSEE],
*[source:lit                   ][!lit],
*[source:hgv                   ][!hgv],
*[source:highway               ][!highway],
*[source:maxaxleload           ][!maxaxleload],
*[source:surface               ][!surface],
*[source:bridge                ][!bridge],
*[source:old_name              ][!old_name],
*[source:bicycle               ][!bicycle],
*[source:designation           ][!designation],
*[source:height                ][!height],
*[source:lanes                 ][!lanes],
*[source:postcode              ][!addr:postcode],
*[source:housenumber           ][!addr:housenumber],
*[source:addr:postcode         ][!addr:postcode],
*[source:addr:housenumber      ][!addr:housenumber],
*[source:addr                  ][!/^addr:/],
*[source:maxspeed              ][!/^maxspeed:?/] {
  throwWarning: tr("{0} without {1}", "{0.key}", "{1.key}");
  assertMatch: "way lanes=42";
  assertNoMatch: "way lanes=42 highway=unclassified";
  assertMatch: "node source:addr:postcode=postman";
  assertMatch: "node source:addr=postman";
  assertNoMatch: "node source:addr=postman addr:housenumber=42";
}

/* {0.key} without {1.key} (info level) */
*[lanes:forward][!lanes:backward][oneway!=yes][oneway!=-1],
*[lanes:backward][!lanes:forward][oneway!=yes][oneway!=-1],
*[leaf_type ][!leaf_cycle],
*[leaf_cycle][!leaf_type] {
  throwOther: tr("{0} without {1}", "{0.key}", "{1.key}");
}

/* {0.key} without {1.tag} */
*[fence_type                   ][barrier!=fence],
*[recycling_type               ][amenity!=recycling],
*[information                  ][tourism!=information],
*[board_type                   ][information!=board],
*[shelter_type                 ][amenity!=shelter],
*[lamp_type                    ][highway!=street_lamp],
*[map_type                     ][information!=map],
*[site_type                    ][historic!=archaeological_site],
*[artwork_type                 ][tourism!=artwork],
*[castle_type                  ][historic!=castle],
*[reservoir_type               ][landuse!=reservoir][water!=reservoir],
*[bridge:movable               ][bridge!=movable],
*[parking                      ][amenity!~/^(parking|parking_space|parking_entrance|motorcycle_parking)$/],
*[cutline                      ][man_made!=cutline],
*[bunker_type                  ][military!=bunker] {
  throwWarning: tr("{0} without {1}", "{0.key}", "{1.tag}");
}

/* {0.tag} without {1.key} (warning level) */
*[tourism=information][!information],
*[aeroway=terminal][!building],
*[power=generator][!generator:source],
*[amenity=place_of_worship][!religion] {
  throwWarning: tr("{0} without {1}", "{0.tag}", "{1.key}");
}

/* {0.tag} without {1.key} (info level) */
*[amenity=parking              ][!parking],
*[amenity=parking_entrance     ][!parking] {
  throwOther: tr("{0} without {1}", "{0.tag}", "{1.key}");
}

/* {0.key} without {1.key} or {2.key} */
*[incline                      ][!highway][!railway],
*[oneway                       ][!highway][!railway] {
  throwWarning: tr("{0} without {1} or {2}", "{0.key}", "{1.key}", "{2.key}");
}

/* {0.key} without {1.key} or {2.tag} */
*[smoothness                   ][!highway][amenity!~/^(parking|parking_space|parking_entrance|motorcycle_parking)$/],
*[segregated                   ][!highway][railway!=crossing],
*[boat                         ][!waterway][natural!=water] {
  throwWarning: tr("{0} without {1} or {2}", "{0.key}", "{1.key}", "{2.tag}");
}

/* {0.tag} without {1.tag} or {2.tag} */
*[amenity=recycling][recycling_type!=container][recycling_type!=centre] {
  throwWarning: tr("{0} without {1} or {2}", "{0.tag}", "{1.tag}", "{2.tag}");
}

/* {0.key} without {1.key}, {2.tag} or {3.tag} */
*[intermittent                 ][!waterway][natural!~/^(water|spring)$/][ford!=yes] {
  throwWarning: tr("{0} without {1}, {2} or {3}", "{0.key}", "{1.key}", "{2.tag}", "{3.tag}");
}

/* {0.key} without {1.key}, {2.key} or {3.key} */
*[snowplowing                  ][!highway][!amenity][!leisure] {
  throwWarning: tr("{0} without {1}, {2} or {3}", "{0.key}", "{1.key}", "{2.key}", "{3.key}");
}

/* {0.key} without {1.key}, {2.key} or {3.tag} */
*[toll                         ][!highway][!barrier][route!~/^(ferry|road)$/] {
  throwWarning: tr("{0} without {1}, {2} or {3}", "{0.key}", "{1.key}", "{2.key}", "{3.tag}");
}

/* {0.tag} together with {1.key}, see #10837 */
*[noname?][name] {
  throwWarning: tr("{0} together with {1}", "{0.tag}", "{1.key}");
}

/* {0.tag} together with {1.key}, see #9389 */
*[oneway=yes][/:backward/],
*[oneway=yes][/:forward/],
*[oneway=-1 ][/:backward/],
*[oneway=-1 ][/:forward/] {
  throwWarning: tr("{0} together with {1}", "{0.tag}", "{1.key}");
}

/* {0.tag} together with {1.tag} (info level), see #9696 */
*[highway=footway][oneway=no] {
  throwOther: tr("{0} together with {1}", "{0.tag}", "{1.tag}");
}

/* {0.tag} together with {1.tag}, see #10186 */
*[highway=footway][bicycle=designated] {
  throwWarning: tr("{0} together with {1}", "{0.tag}", "{1.tag}");
}

/*see #11127*/
way[waterway][bridge=yes] {
  throwWarning: tr("{0} together with {1}", "{0.key}", "{1.tag}");
  suggestAlternative: "bridge=aqueduct";
  fixAdd: "bridge=aqueduct";
}

/* only {0.key}, see #11104 */
*[area][eval(number_of_tags()) = 1],
*[name][eval(number_of_tags()) = 1],
*[ref][eval(number_of_tags()) = 1] {
  throwWarning: tr("incomplete object: only {0}", "{0.key}");
}
/* only {0.key} and {1.key}, see #11104 */
*[name][area][eval(number_of_tags()) = 2],
*[name][ref][eval(number_of_tags()) = 2] {
  throwWarning: tr("incomplete object: only {0} and {1}", "{0.key}", "{1.key}");
}

/* see #9811 */
*[place][place!=farm][/^addr:/],
*[boundary][/^addr:/],
*[highway][/^addr:/][highway!=services][highway!=rest_area] {
  throwWarning: tr("{0} together with addr:*", "{0.key}");
}

/* see #9195 */
*[highway=footway][cycleway=lane] {
  throwWarning: tr("{0} together with {1}", "{0.tag}", "{1.tag}");
  suggestAlternative: "highway=path + foot=designated + bicycle=designated + segregated=yes";
}

/* {0} on suspicious object */
*[tunnel  ][!highway][!railway][!waterway][public_transport != platform][man_made != pipeline],
*[bridge  ][!highway][!railway][!waterway][!piste:type][public_transport != platform][man_made !~ /^(bridge|pipeline)$/][building != bridge],
*[psv     ][!highway][!railway][!waterway][amenity !~ /^parking.*/],
*[width   ][!highway][!railway][!waterway][!aeroway][!cycleway][!footway][!barrier][!man_made][!entrance],
*[maxspeed][!highway][!railway][traffic_sign !~ /^(.*;)?maxspeed(;.*)?$/][type != enforcement][waterway !~ /^(river|canal|lock)$/][!traffic_calming],
*[lit     ][!highway][!railway][!piste:type][!amenity][public_transport!=platform][advertising!=billboard][!leisure][!tourism] {
  throwWarning: tr("{0} on suspicious object", "{0.key}");
}

node[amenity =~ /^(restaurant|cafe|fast_food)$/][!name][noname!=yes] {
  throwOther: tr("restaurant without name");
  assertMatch: "node amenity=restaurant";
  assertNoMatch: "node amenity=restaurant noname=yes";
  assertNoMatch: "node amenity=restaurant name=Foobar";
}

way[highway][barrier],
*[highway][waterway][waterway!=dam],
way[highway][natural],
*[landuse][building] {
  throwWarning: tr("{0} used with {1}", "{0.key}", "{1.key}");
  assertNoMatch: "node highway=street_lamp natural=birds_nest note=josm#10193";
}

*[natural=water][leisure=swimming_pool],
*[natural=water][amenity=swimming_pool] {
  /* see #6932 */
  throwWarning: tr("natural water used for swimming pool");
  fixRemove: "natural";
}

/* see #9593, #11183 */
*[sport][!building][!club][tourism != hotel][highway != raceway][leisure !~ /^(sports_centre|stadium|track|pitch|golf_course|water_park|swimming_pool|recreation_ground|ice_rink)$/][natural !~ /^(beach|bare_rock|peak)$/][amenity !~ /^(pub|restaurant|swimming_pool)$/][landuse !~ /^(recreation_ground|piste|farm|farmland)$/][barrier !~ /^(wall|retaining_wall)$/][!"piste:type"] {
    throwWarning: tr("sport without physical feature");
    assertMatch: "node sport=tennis";
    assertNoMatch: "node sport=tennis leisure=pitch";
    assertNoMatch: "node sport=beachvolleyball natural=beach";
    assertNoMatch: "node sport=skiiing landuse=piste";
    assertNoMatch: "node sport=swimming tourism=hotel";
    assertNoMatch: "node sport=10pin amenity=restaurant";
}

/* see #10140 */
*[building:levels][!building][!building:part] {
  throwWarning: tr("{0} without {1} or {2}", "{0.key}", "{1.key}", "{2.key}");
}

/* see #10471 */
way[waterway] > node[ford?] { set ford_on_waterway; }
way[highway] > node[ford?] { set ford_on_highway; }
node[ford?]!.ford_on_waterway, node[ford?]!.ford_on_highway {
    throwWarning: tr("{0} should be on the node where {1} and {2} intersect", "ford", "highway", "waterway");
}

/* any other *_name tag (except old_name, loc_name and uic_name) but not a name , see #10837 #11297 */
*[/_name$/][!name][!old_name][!loc_name][!uic_name][!artist_name][noname!=yes] {
  throwWarning: tr("alternative name without {0}", "{1.key}");
}

/* see #10837 */
way[destination][!oneway?] {
  throwWarning: tr("incomplete usage of {0} on a way without {1}", "{0.key}", "{1.key}");
  suggestAlternative: "destination:forward";
  suggestAlternative: "destination:backward";
}