new-lines: refactor to reduce duplicate code

Both options where using identical code.  Now the newline character
is determined beforehand depending on the selected option and then
the same code can be used for all options
pull/474/head
Jan Wille 3 years ago
parent 237eefba73
commit 49f029ea99
No known key found for this signature in database
GPG Key ID: 9D2FEBCFD72E715B

@ -41,13 +41,13 @@ DEFAULT = {'type': 'unix'}
def check(conf, line):
if conf['type'] == 'unix':
newline_char = '\n'
elif conf['type'] == 'dos':
newline_char = '\r\n'
if line.start == 0 and len(line.buffer) > line.end:
if conf['type'] == 'dos':
if (line.end + 2 > len(line.buffer) or
line.buffer[line.end:line.end + 2] != '\r\n'):
yield LintProblem(1, line.end - line.start + 1,
'wrong new line character: expected \\r\\n')
else:
if line.buffer[line.end] != '\n':
yield LintProblem(1, line.end - line.start + 1,
'wrong new line character: expected \\n')
if line.buffer[line.end:line.end + len(newline_char)] != newline_char:
yield LintProblem(1, line.end - line.start + 1,
'wrong new line character: expected {}'
.format(repr(newline_char).strip('\'')))

Loading…
Cancel
Save