mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-20 01:24:42 +04:00
Address review comments
This commit is contained in:
parent
55c74c10d9
commit
55ef3ce960
1 changed files with 6 additions and 10 deletions
|
|
@ -34,17 +34,13 @@ def _process_filename_at_once(pattern, filename):
|
||||||
match = pattern.search(contents)
|
match = pattern.search(contents)
|
||||||
if match:
|
if match:
|
||||||
retv = 1
|
retv = 1
|
||||||
line_no = len(
|
line_no = contents[:match.start()].count(b'\n')
|
||||||
re.compile('\n'.encode()).findall(contents, 0, match.start()),
|
output.write('{}:{}:'.format(filename, line_no + 1))
|
||||||
)
|
|
||||||
output.write(
|
|
||||||
'{}:{}:'.format(filename, line_no + 1),
|
|
||||||
)
|
|
||||||
|
|
||||||
matched_lines = match.group().split('\n')
|
matched_lines = match.group().split(b'\n')
|
||||||
matched_lines[0] = contents.split('\n')[line_no]
|
matched_lines[0] = contents.split(b'\n')[line_no]
|
||||||
|
|
||||||
output.write_line('\n'.join(matched_lines))
|
output.write_line(b'\n'.join(matched_lines))
|
||||||
return retv
|
return retv
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -70,7 +66,7 @@ def main(argv=None):
|
||||||
|
|
||||||
flags = re.IGNORECASE if args.ignore_case else 0
|
flags = re.IGNORECASE if args.ignore_case else 0
|
||||||
if args.multiline:
|
if args.multiline:
|
||||||
flags = flags | re.MULTILINE | re.DOTALL
|
flags |= re.MULTILINE | re.DOTALL
|
||||||
|
|
||||||
pattern = re.compile(args.pattern.encode(), flags)
|
pattern = re.compile(args.pattern.encode(), flags)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue