wmllint: clean up detection of "illegal children of [if]"

Previously, only lines that parse_attribute could process got passed to
local_sanity_check. So tags survived as ancestors of attribute lines, but
the lines with the tags themselves got discarded. Hence, the "illegal child
of [if]" error was actually triggered by attributes, and the line number
referred to that line rather than the child tag.

While working on [aspect] and [facet] (which originally preceded this commit),
I changed the TypeError exception to pass all lines to local_sanity_check. This
allows for a direct test of the child tags. It turns out many child tags were
not tested because all the attributes were nested deeper inside other tags,
so that the child tag was not the parent of any attribute.

Two core macros failed the new test with the tags [filter_second] and
[filter_second_attack]. This pointed up the fact that these were not in the
list of valid child tags.

It also turns out that tags inside #ifdefs didn't fit the original test,
because "#ifdef" was considered an ancestor, interrupting the link between
"[if]" and the child tag.
This commit is contained in:
Groggy Dice 2013-12-22 21:31:27 -05:00
parent 98abe1ea42
commit b68feb74f4

View file

@ -948,11 +948,13 @@ def local_sanity_check(filename, nav, key, prefix, value, comment):
if "[part]" in ancestors and parent not in ("[part]", "[image]", "[insert_tag]", "[if]", "[then]", "[else]", "[switch]", "[case]", "[variable]", "[deprecated_message]") and not parent.startswith("#"):
print errlead + '%s not permitted within [part] tag' % parent
# Most tags are not permitted inside [if]
if len(ancestors) >= 2 and ancestors[-1] == "[if]":
if parent not in ("[and]", "[else]", "[frame]", "[have_location]",
if (len(ancestors) >= 1 and parent == "[if]") or \
(len(ancestors) >= 2 and parent == "#ifdef" and ancestors[-1] == "[if]"):
if isOpener(nav.element) and nav.element not in ("[and]",
"[else]", "[frame]", "[have_location]",
"[have_unit]", "[not]", "[or]", "[then]",
"[variable]") and not parent.endswith("_frame]"):
print errlead + 'illegal child of [if]'
"[variable]") and not nav.element.endswith("_frame]") and not nav.element.startswith("[filter"):
print errlead + 'illegal child of [if]:', nav.element
# Check for fluky credit parts
if parent == "[entry]":
if key == "email" and " " in value:
@ -2241,7 +2243,8 @@ def translator(filename, mapxforms, textxform):
(key, prefix, value, comment) = parse_attribute(nav.text)
local_sanity_check(filename, nav, key, prefix, value, comment)
except TypeError:
pass
key = prefix = value = comment = None
local_sanity_check(filename, nav, key, prefix, value, comment)
# Perform file-global semantic sanity checks
newdata = global_sanity_check(filename, newdata)
# OK, now perform WML rewrites