create a magic comment for appending custom usage classes

This will keep non-core usage types from being described as a "non-standard usage class" in recruitment error messages. These error messages will only be triggered if there is a mismatch between recruits and recruitment patterns, so this magic comment is low-priority.

It was suggested that wmllint could auto-detect new usage values in unit files, and automatically append them to the list of recognized usage types. This was rejected because of the possibility of adding misspelled or mistaken usage types.
This commit is contained in:
Groggy Dice 2013-12-15 10:26:19 -05:00
parent 990ac9a901
commit 096417df47

View file

@ -99,6 +99,13 @@
# declaration will be useful if you are declaring units with macros that
# include a substitutable formal in the unit name; there are examples in UtBS.
#
# If a mismatch between a recruit list and recruitment pattern involves a
# usage type outside the five core types, the warning message will include a
# note that a non-standard usage class is involved. If you are using custom
# usage classes and would like wmllint to be aware of them, you can insert
# the magic comment, "wmllint: usagetype <class>". This comment will take a
# comma-separated list, and can also be pluralized to "usagetypes".
#
# You can disable stack-based malformation checks with a comment
# containing "wmllint: validate-off" and re-enable with "wmllint: validate-on".
#
@ -1259,6 +1266,11 @@ def global_sanity_check(filename, lines):
if m:
usage[m.group(1)] = m.group(2).strip()
unit_types.append(m.group(1))
# Magic comment for adding non-standard usage types
m = re.search('# *wmllint: usagetypes? +(.*)', lines[i])
if m:
for newusage in m.group(1).split(","):
usage_types.append(newusage.strip())
# Accumulate global spelling exceptions
words = re.search("wmllint: general spellings? (.*)", lines[i])
if words: