зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1716551 - Improve Fluent linter behavior with single and double quotes, r=dminor
- Don't throw when a placeable is enclosed in double straight quotes - Catch single quotes used as genitive on plural nouns Differential Revision: https://phabricator.services.mozilla.com/D117898
This commit is contained in:
Родитель
5c92b47db4
Коммит
2395c9bd16
|
@ -49,10 +49,10 @@ class Linter(visitor.Visitor):
|
|||
|
||||
self.results = []
|
||||
self.identifier_re = re.compile(r"[a-z0-9-]+")
|
||||
self.apostrophe_re = re.compile(r"\w\'\w")
|
||||
self.apostrophe_re = re.compile(r"\w'")
|
||||
self.incorrect_apostrophe_re = re.compile(r"\w\u2018\w")
|
||||
self.single_quote_re = re.compile(r"'.+'")
|
||||
self.double_quote_re = re.compile(r"\"")
|
||||
self.single_quote_re = re.compile(r"'(.+)'")
|
||||
self.double_quote_re = re.compile(r"\".+\"")
|
||||
self.ellipsis_re = re.compile(r"\.\.\.")
|
||||
|
||||
self.minimum_id_length = 9
|
||||
|
@ -139,7 +139,10 @@ class Linter(visitor.Visitor):
|
|||
parser = TextElementHTMLParser()
|
||||
parser.feed(node.value)
|
||||
for text in parser.extracted_text:
|
||||
if self.apostrophe_re.search(text):
|
||||
# To check for apostrophes, first remove pairs of straight quotes
|
||||
# used as delimiters.
|
||||
cleaned_str = re.sub(self.single_quote_re, "\1", node.value)
|
||||
if self.apostrophe_re.search(cleaned_str):
|
||||
self.add_error(
|
||||
node,
|
||||
"TE01",
|
||||
|
|
|
@ -3,6 +3,7 @@ blah-blah = This is a legal identifier.
|
|||
blah_blah = Underscores in identifiers are not permitted.
|
||||
|
||||
bad-apostrophe-1 = The bee's knees
|
||||
bad-apostrophe-end-1 = The bees' knees
|
||||
bad-apostrophe-2 = The bee‘s knees
|
||||
bad-single-quote = 'The bee’s knees'
|
||||
ok-apostrophe = The bee’s knees
|
||||
|
@ -39,3 +40,5 @@ identifiers-in-selectors-should-be-ignored =
|
|||
|
||||
this-message-reference-is-ignored =
|
||||
.label = { menu-quit.label }
|
||||
|
||||
ok-message-with-html-and-var = This is a <a href="{ $url }">link</a>
|
||||
|
|
|
@ -16,7 +16,7 @@ def test_lint_exclusions(lint, paths):
|
|||
|
||||
def test_lint_single_file(lint, paths):
|
||||
results = lint(paths("bad.ftl"))
|
||||
assert len(results) == 10
|
||||
assert len(results) == 11
|
||||
assert results[0].rule == "ID01"
|
||||
assert results[0].lineno == 1
|
||||
assert results[0].column == 1
|
||||
|
@ -26,27 +26,30 @@ def test_lint_single_file(lint, paths):
|
|||
assert results[2].rule == "TE01"
|
||||
assert results[2].lineno == 5
|
||||
assert results[2].column == 20
|
||||
assert results[3].rule == "TE02"
|
||||
assert results[3].rule == "TE01"
|
||||
assert results[3].lineno == 6
|
||||
assert results[3].column == 20
|
||||
assert results[4].rule == "TE03"
|
||||
assert results[3].column == 24
|
||||
assert results[4].rule == "TE02"
|
||||
assert results[4].lineno == 7
|
||||
assert results[4].column == 20
|
||||
assert results[5].rule == "TE04"
|
||||
assert results[5].lineno == 10
|
||||
assert results[5].rule == "TE03"
|
||||
assert results[5].lineno == 8
|
||||
assert results[5].column == 20
|
||||
assert results[6].rule == "TE05"
|
||||
assert results[6].lineno == 12
|
||||
assert results[6].column == 16
|
||||
assert results[7].rule == "TE03"
|
||||
assert results[7].lineno == 16
|
||||
assert results[7].column == 20
|
||||
assert results[6].rule == "TE04"
|
||||
assert results[6].lineno == 11
|
||||
assert results[6].column == 20
|
||||
assert results[7].rule == "TE05"
|
||||
assert results[7].lineno == 13
|
||||
assert results[7].column == 16
|
||||
assert results[8].rule == "TE03"
|
||||
assert results[8].lineno == 24
|
||||
assert results[8].column == 18
|
||||
assert results[9].rule == "ID02"
|
||||
assert results[9].lineno == 31
|
||||
assert results[9].column == 1
|
||||
assert results[8].lineno == 17
|
||||
assert results[8].column == 20
|
||||
assert results[9].rule == "TE03"
|
||||
assert results[9].lineno == 25
|
||||
assert results[9].column == 18
|
||||
assert results[10].rule == "ID02"
|
||||
assert results[10].lineno == 32
|
||||
assert results[10].column == 1
|
||||
|
||||
|
||||
def test_comment_group(lint, paths):
|
||||
|
|
Загрузка…
Ссылка в новой задаче