better deal with CRLF/LF issues

This commit is contained in:
Moritz Raabe
2021-03-19 09:19:50 +01:00
parent c7798b3254
commit 7e0b5236af
3 changed files with 10 additions and 1 deletions

View File

@@ -736,6 +736,8 @@ class Rule(object):
# the below regex makes these adjustments and while ugly, we don't have to explore the ruamel.yaml insides
doc = re.sub(r"!!int '0x-([0-9a-fA-F]+)'", r"-0x\1", doc)
# normalize CRLF to LF
doc = doc.replace("\r\n", "\n")
return doc

View File

@@ -65,6 +65,8 @@ def main(argv=None):
return 0
else:
logger.info("rule requires reformatting (%s)", rule.name)
if "\r\n" in rule.definition:
logger.info("please make sure that the file uses LF (\\n) line endings only")
return 1
if args.in_place:

View File

@@ -331,7 +331,12 @@ class FormatIncorrect(Lint):
if actual != expected:
diff = difflib.ndiff(actual.splitlines(1), expected.splitlines(True))
self.recommendation = self.recommendation_template.format("".join(diff))
recommendation_template = self.recommendation_template
if "\r\n" in actual:
recommendation_template = (
self.recommendation_template + "\nplease make sure that the file uses LF (\\n) line endings only"
)
self.recommendation = recommendation_template.format("".join(diff))
return True
return False