wiki:Help/Validator/MapCSSTagChecker

Version 13 (modified by Klumbumbus, 9 years ago) ( diff )

improve example

Languages:

This tagchecker is considered to be the successor of the tagchecker.cfg and uses much of the MapCSS implementation for stylesheets. The official extension for files is *.validator.mapcss.

The main implementation ticket was #9414.

Syntax

selector {
   /* exactly one of */
   throwError: "message";
   throwWarning: "message";
   throwOther: "message";

   /* arbitrarily many of */
   fixAdd: "key=val";
   fixRemove: "key";
   fixChangeKey: "old=>new";
   suggestAlternative: "any text (e.g., alternative key)";

   /* assertions for unit tests */
   assertMatch: "node/way/relation key1=value1 keyN=valueN";
   assertNoMatch: "node/way/relation key1=value1 keyN=valueN";
}

Some more details:

  • The syntax of selectors is specified in #Selectors
  • Alternatively to strings on the right hand side of those expressions, expressions are evaluated (see list+syntax)
    • Most useful of all is tr() in order to have those strings translated
  • If at least one fixAdd/fixRemove/fixChangeKey is specified, those changes are executed for objects matching this test when you press the fix button in the Validator Dialog.
  • If suggestAlternative is/are present, those alternatives are displayed together with the test message
  • assertMatch and assertNoMatch: You can give there examples, which should (assertMatch) or should not (assertNoMatch) match the used selector. So this is a test if the selector works correct for the given example. Normally this is only usefull for more complex selectors and less for simple key-value selectors. The tests are executed in the context of unit tests and on ​http://donvip.fr/jenkins/job/JOSM/. They are also executed for local validator files if the advanced option validator.check_assert_local_rules is set to "true" in the advanced preferences (see #10206). If you enabled this option and the test fails, you will get a message in the console output which can look like: WARNUNG: Expecting test '...' to match way ... or ...to not match....

Placeholders

  • They are used to simplify the translation and make it less error-prone.
  • The placeholders in the warning message e.g. {3} are written with ascending numbers, starting at 0. So: 0 1 2 3 4... This is the id of the placeholder.
  • After the warning message (separated by a comma), you need to define the contents of the placeholders.
  • At first you define the content of the first placeholder (the one with the id 0). Then you define the content of the second placeholder (the one with the id 1), and so on.
  • You need to specify which selector you want to use in the placeholder and if you want to use the key ({i.key}), the value ({i.value}) or the whole tag ({i.tag}) of the selector. Counting starts at 0. So, {4.value} means the value of the 5th selector.
  • Classes and pseudoclasses do also count.
  • You can use {i.tag} also for key only selectors, but this will lead to the following output: key= (without the actual value, see #10859)
  • If you use regular expressions in the selector and use this in a placeholder, you will also see the regex code in the warning message (see #9782)

example:

*[a=b][c=d][e][f=g] {
  throwWarning: tr("{0} BLA {1} BLUB {2} BLIB {3}", "{1.tag}", "{0.key}", "{2.key}", "{3.value}");
}

This will evaluate to c=d BLA a BLUB e BLIB g

Examples

See *.mapcss files in source:trunk/data/validator/ for the checks included in JOSM's core.

*[barrier=wire_fence] {
  throwWarning: tr("{0} is deprecated", "{0.tag}"); /* "{0.tag}" evaluates to "barrier=wire_fence" */
  fixAdd: "barrier=fence";
  fixAdd: "fence_type=chain_link";
  assertMatch: "way barrier=wire_fence";
  assertNoMatch: "way barrier=fence";
}

use of classes:

way[highway=~/^(motorway|trunk|primary|secondary|tertiary)$/] {
  set major_road;
}
way.major_road[!ref] {
  throwOther: tr("highway without {0}", "{1.key}"); /* the class ".major:road" is the 0th selector and "!ref" is the 1st selector. The output is: "highway without ref" */
  assertMatch: "way highway=primary";
  assertNoMatch: "way highway=primary ref=123";
}

See also

Attachments (1)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.