Make punctuation customizable per language

This commit is contained in:
Emil Lundberg 2023-11-02 15:20:31 +01:00
parent a9a3ac7ecf
commit 7462f0f0b7
No known key found for this signature in database
GPG Key ID: 0F47E61493A9B8E5
2 changed files with 8 additions and 4 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):
def check_prefixes(k, v, s_max_words, s_max_len, punctuation, q_endings):
errs = []
if k.startswith("s_"):
if len(v) > s_max_len:
@ -53,11 +53,11 @@ def check_prefixes(k, v, s_max_words, s_max_len):
if ". " in v:
errs.append("Spans multiple sentences")
elif k.startswith("p_"):
if v[-1] not in ".!":
if punctuation and not any(v.endswith(p) for p in punctuation):
errs.append("Doesn't end in punctuation")
elif k.startswith("q_"):
if not v.endswith("?"):
errs.append("Doesn't end in '?'")
if q_endings and not any(v.endswith(q) for q in q_endings):
errs.append("Doesn't end in question mark.")
return errs
@ -79,6 +79,8 @@ def lint_strings(strings, rules):
v,
rules.get("s_max_words", 4),
rules.get("s_max_len", 32),
rules.get("punctuation", [".", "!"]),
rules.get("q_endings", ["?"]),
)
)
errs.extend(check_misc(k, v))

View File

@ -16,6 +16,8 @@
},
"@_lint_rules": {
"punctuation": ["。", ""],
"q_endings": ["?", ""],
"s_max_words": 4,
"s_max_length": 32
},