mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 13:44:17 +00:00
Merge pull request #15 from pre-commit/cross_platform_trim_trailing_whitespace
Use fileinput instead of sed.
This commit is contained in:
commit
2bd608119f
1 changed files with 7 additions and 1 deletions
|
|
@ -1,12 +1,18 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import fileinput
|
||||||
import sys
|
import sys
|
||||||
from plumbum import local
|
from plumbum import local
|
||||||
|
|
||||||
from pre_commit_hooks.util import entry
|
from pre_commit_hooks.util import entry
|
||||||
|
|
||||||
|
|
||||||
|
def _fix_file(filename):
|
||||||
|
for line in fileinput.input([filename], inplace=True):
|
||||||
|
print(line.rstrip())
|
||||||
|
|
||||||
|
|
||||||
@entry
|
@entry
|
||||||
def fix_trailing_whitespace(argv):
|
def fix_trailing_whitespace(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
@ -20,7 +26,7 @@ def fix_trailing_whitespace(argv):
|
||||||
if bad_whitespace_files:
|
if bad_whitespace_files:
|
||||||
for bad_whitespace_file in bad_whitespace_files:
|
for bad_whitespace_file in bad_whitespace_files:
|
||||||
print('Fixing {0}'.format(bad_whitespace_file))
|
print('Fixing {0}'.format(bad_whitespace_file))
|
||||||
local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
|
_fix_file(bad_whitespace_file)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue