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
This commit is contained in:
@@ -41,13 +41,13 @@ DEFAULT = {'type': 'unix'}
|
|||||||
|
|
||||||
|
|
||||||
def check(conf, line):
|
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 line.start == 0 and len(line.buffer) > line.end:
|
||||||
if conf['type'] == 'dos':
|
if line.buffer[line.end:line.end + len(newline_char)] != newline_char:
|
||||||
if (line.end + 2 > len(line.buffer) or
|
yield LintProblem(1, line.end - line.start + 1,
|
||||||
line.buffer[line.end:line.end + 2] != '\r\n'):
|
'wrong new line character: expected {}'
|
||||||
yield LintProblem(1, line.end - line.start + 1,
|
.format(repr(newline_char).strip('\'')))
|
||||||
'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')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user