Use strings for lint punctuation customization

This will be needed for this to be compatible with the JSON-based ARB
reformatter, which requires all lists to be of equal length in order for
whitespace to line up.
This commit is contained in:
Emil Lundberg 2023-11-02 16:13:08 +01:00
parent 97265d24db
commit d5a59392c0
No known key found for this signature in database
GPG Key ID: 0F47E61493A9B8E5
3 changed files with 9 additions and 9 deletions

View File

@ -40,7 +40,7 @@ def check_duplicate_values(strings):
seen[v] = k
def check_prefixes(k, v, s_max_words, s_max_len, p_endings, q_endings):
def check_prefixes(k, v, s_max_words, s_max_len, p_ending_chars, q_ending_chars):
errs = []
if k.startswith("s_"):
if len(v) > s_max_len:
@ -53,10 +53,10 @@ def check_prefixes(k, v, s_max_words, s_max_len, p_endings, q_endings):
if ". " in v:
errs.append("Spans multiple sentences")
elif k.startswith("p_"):
if p_endings and not any(v.endswith(p) for p in p_endings):
if p_ending_chars and not any(v.endswith(p) for p in p_ending_chars):
errs.append("Doesn't end in punctuation")
elif k.startswith("q_"):
if q_endings and not any(v.endswith(q) for q in q_endings):
if q_ending_chars and not any(v.endswith(q) for q in q_ending_chars):
errs.append("Doesn't end in question mark.")
return errs
@ -79,8 +79,8 @@ def lint_strings(strings, rules):
v,
rules.get("s_max_words", 4),
rules.get("s_max_len", 32),
rules.get("p_endings", [".", "!"]),
rules.get("q_endings", ["?"]),
rules.get("p_ending_chars", ".!"),
rules.get("q_ending_chars", "?"),
)
)
errs.extend(check_misc(k, v))

View File

@ -16,8 +16,8 @@
},
"@_lint_rules": {
"p_endings": [".", "!"],
"q_endings": ["?"],
"p_ending_chars": ".!",
"q_ending_chars": "?",
"s_max_words": 4,
"s_max_length": 32
},

View File

@ -16,8 +16,8 @@
},
"@_lint_rules": {
"p_endings": ["。", ""],
"q_endings": ["?", ""],
"p_ending_chars": "。!",
"q_ending_chars": "?",
"s_max_words": 4,
"s_max_length": 32
},