Skip to content

Commit

Permalink
fix E103 to handle double braces
Browse files Browse the repository at this point in the history
  • Loading branch information
eviljeff committed Jun 21, 2022
1 parent c90b8cd commit cab3e7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dennis/linter.py
@@ -1,4 +1,5 @@
import re
import uuid
from collections import namedtuple
from itertools import zip_longest

Expand Down Expand Up @@ -195,16 +196,25 @@ def lint(self, vartok, linted_entry):
return []

malformed_re = re.compile(r"(?:(?:^|\})[^\{]*\})")
double_open = str(uuid.uuid4())
double_close = str(uuid.uuid4())

for trstr in linted_entry.strs:
if not trstr.msgstr_string:
continue

malformed = malformed_re.findall(trstr.msgstr_string)
malformed = malformed_re.findall(
trstr.msgstr_string.replace("{{", double_open).replace(
"}}", double_close
)
)
if not malformed:
continue

malformed = [item.strip() for item in malformed]
malformed = [
item.strip().replace(double_open, "{{").replace(double_close, "}}")
for item in malformed
]
msgs.append(
LintMessage(
ERROR,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_linter.py
Expand Up @@ -335,6 +335,15 @@ def test_python_var_missing_left_curly_brace(self):
assert msgs[0].code == "E103"
assert msgs[0].msg == "missing left curly-brace: }}"

def test_double_braces(self):
linted_entry = build_linted_entry(
'msgid "This is {{literal}} brace, {0}, and {{another}}."\n'
'msgstr "This is {{literal}} brace, {0}, and {{another}}."\n'
)

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

def test_varformat_empty(self):
vartok = VariableTokenizer([])

Expand Down

0 comments on commit cab3e7c

Please sign in to comment.