Skip to content

Commit

Permalink
wmllint: don't try to collect WML tags inside Lua code
Browse files Browse the repository at this point in the history
Fixes #5509
  • Loading branch information
Elvish-Hunter committed Feb 16, 2021
1 parent a0ee38a commit 2a83e78
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion data/tools/wmllint
Expand Up @@ -2800,6 +2800,7 @@ def translator(filename, mapxforms, textxform):
cont = False
validate = True
unbalanced = False
in_lua_code = False
newdata = []
refname = None
while mfile:
Expand Down Expand Up @@ -2930,7 +2931,7 @@ def translator(filename, mapxforms, textxform):
# Now do warnings based on the state of the tag stack.
# the regex check for "path=" is needed due to [modify_ai]
# which uses square braces in its syntax
if not unbalanced and not re.match(r"\s*path\=", destringed):
if not unbalanced and not in_lua_code and not re.match(r"\s*path\=", destringed):
for instance in re.finditer(r"\[\/?\+?([a-z][a-z_]*[a-z])\]", destringed):
tag = instance.group(1)
closer = instance.group(0)[1] == '/'
Expand Down Expand Up @@ -2959,6 +2960,14 @@ def translator(filename, mapxforms, textxform):
unbalanced = True
if "wmllint: unbalanced-off" in comment:
unbalanced = False
# single line of Lua code, skip
if re.match(r"\s*?code\s?=\s?<<.*>>", destringed):
continue
# multiline Lua block
if re.match(r"\s*?code\s?=\s?<<.*", destringed):
in_lua_code = True
if in_lua_code and re.match(r".*?>>\s*$", destringed):
in_lua_code = False
if "wmllint: match" in comment:
comment = comment.strip()
try:
Expand Down

1 comment on commit 2a83e78

@CelticMinstrel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one technicality - it's possible for a Lua block to end and a new one to start on the same line. There are very few reasons to do that, mind you, so I'm not sure if it's important, but swapping the order of the multiline checks would probably catch most instances of it.

Please sign in to comment.