Skip to content

Commit

Permalink
Fix false positive wit' InvalidVarsLintRule
Browse files Browse the repository at this point in the history
If tharr bee nay variables in th' msgid, then "invalid" and "malform'd"
variables in th' msgstrr bee false positives.

Fixes #78
  • Loading branch information
willkg committed Oct 27, 2015
1 parent 581f230 commit aca57f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dennis/linter.py
Expand Up @@ -449,6 +449,11 @@ def lint(self, vartok, linted_entry):
continue

msgid_tokens = vartok.extract_tokens(' '.join(trstr.msgid_strings))
# If this is python-format or python-brace-format and there are
# no tokens in the msgid, then "no tokens, no problem".
if not msgid_tokens:
continue

msgstr_tokens = vartok.extract_tokens(trstr.msgstr_string)

invalid = msgstr_tokens.difference(msgid_tokens)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_linter.py
Expand Up @@ -495,7 +495,7 @@ def test_fine(self):
def test_invalid(self):
linted_entry = build_linted_entry(
'#: foo/foo.py:5\n'
'msgid "Foo"\n'
'msgid "Foo {bar}"\n'
'msgstr "Oof: {foo}"\n')

msgs = self.lintrule.lint(self.vartok, linted_entry)
Expand Down Expand Up @@ -564,6 +564,15 @@ def test_urlencoded_urls(self):
msgs = self.lintrule.lint(self.vartok, linted_entry)
assert len(msgs) == 0

def test_msgid_no_vars(self):
linted_entry = build_linted_entry(
'#: foo/foo.py:5\n'
'msgid "http://en.wikipedia.org/wiki/Canvas_element"\n'
'msgstr "http://it.wikipedia.org/wiki/Canvas_%28elemento_HTML%29"\n')

msgs = self.lintrule.lint(self.vartok, linted_entry)
assert len(msgs) == 0


class TestBlankLintRule(LintRuleTestCase):
lintrule = BlankLintRule()
Expand Down

0 comments on commit aca57f6

Please sign in to comment.