refactoring
This commit is contained in:
parent
564c63f0c1
commit
7fc6ba99de
|
@ -61,29 +61,31 @@ class GrammalecteChecker(Checker):
|
|||
result = self.run_grammalecte(filename)
|
||||
if result.stdout:
|
||||
warnings = json.loads(result.stdout)
|
||||
for warning in warnings["data"]:
|
||||
for error in warning["lGrammarErrors"]:
|
||||
if self.filter_out(error):
|
||||
continue
|
||||
item_index = int(warning["iParagraph"]) // 2
|
||||
item = pofile.content[item_index]
|
||||
start = max(0, int(error["nStart"]) - 40)
|
||||
end = max(0, int(error["nEnd"]) + 10)
|
||||
item.add_warning(
|
||||
self.name,
|
||||
# self.name + " " + error["sRuleId"], # TODO
|
||||
error["sMessage"]
|
||||
+ " => ###"
|
||||
+ item.msgstr_rst2txt[start:end]
|
||||
+ "###",
|
||||
)
|
||||
self.manage_grammar_errors(warnings, pofile)
|
||||
Path(filename).unlink()
|
||||
|
||||
def check_item(self, item: PoItem):
|
||||
"""Check an item in a `*.po` file (does nothing)."""
|
||||
pass
|
||||
|
||||
def filter_out(self, error):
|
||||
def manage_grammar_errors(self, warnings, pofile: PoFile):
|
||||
for warning in warnings["data"]:
|
||||
for error in warning["lGrammarErrors"]:
|
||||
if self.filter_out_grammar_error(error):
|
||||
continue
|
||||
item_index = int(warning["iParagraph"]) // 2
|
||||
item = pofile.content[item_index]
|
||||
start = max(0, int(error["nStart"]) - 40)
|
||||
end = max(0, int(error["nEnd"]) + 10)
|
||||
item.add_warning(
|
||||
self.name,
|
||||
error["sMessage"]
|
||||
+ " => ###"
|
||||
+ item.msgstr_rst2txt[start:end]
|
||||
+ "###",
|
||||
)
|
||||
|
||||
def filter_out_grammar_error(self, error):
|
||||
"""Return True when grammalecte error should be ignored."""
|
||||
msg = error["sRuleId"]
|
||||
if msg in (
|
||||
|
|
Loading…
Reference in New Issue
Block a user