Add trailing whitespace fixer.
This commit is contained in:
parent
10c042c99c
commit
acd9eaf6ed
|
@ -1,11 +1,14 @@
|
|||
|
||||
-
|
||||
repo: git@github.com:pre-commit/pre-commit-hooks
|
||||
sha: 5e713f8878b7d100c0e059f8cc34be4fc2e8f897
|
||||
sha: 10c042c99c061b90e4ea11d52e3c5fc93f94b373
|
||||
hooks:
|
||||
-
|
||||
id: pyflakes
|
||||
files: '\.py$'
|
||||
-
|
||||
id: debug-statements
|
||||
files: '\.py$'
|
||||
|
||||
-
|
||||
repo: git@github.com:pre-commit/pre-commit
|
||||
|
|
|
@ -11,3 +11,9 @@
|
|||
description: This hook checks that debug statements (pdb, ipdb, pudb) are not imported on commit.
|
||||
entry: debug-statement-hook
|
||||
language: python
|
||||
-
|
||||
id: trailing-whitespace
|
||||
name: Trim Trailing Whitespace
|
||||
description: This hook trims trailing whitespace.
|
||||
entry: trailing-whitespace-fixer
|
||||
language: python
|
||||
|
|
|
@ -46,7 +46,7 @@ def check_file_for_debug_statements(filename):
|
|||
def debug_statement_hook(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
||||
args = parser.parse_args()
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retv = 0
|
||||
for filename in args.filenames:
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
import argparse
|
||||
import sys
|
||||
from plumbum import local
|
||||
|
||||
|
||||
def fix_trailing_whitespace(argv):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('filenames', nargs='*', help='Filenames to fix')
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
bad_whitespace_files = filter(bool, local['grep'][
|
||||
('-l', '[[:space:]]$') + tuple(args.filenames)
|
||||
](retcode=None).splitlines())
|
||||
|
||||
if bad_whitespace_files:
|
||||
for bad_whitespace_file in bad_whitespace_files:
|
||||
print 'Fixing {0}'.format(bad_whitespace_file)
|
||||
local['sed']['-i', '-e', 's/[[:space:]]*$//', bad_whitespace_file]()
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def entry():
|
||||
fix_trailing_whitespace(sys.argv[1:])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(entry())
|
|
@ -1,4 +1,5 @@
|
|||
argparse
|
||||
plumbum
|
||||
pyflakes
|
||||
simplejson
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -7,12 +7,14 @@ setup(
|
|||
packages=find_packages('.', exclude=('tests*', 'testing*')),
|
||||
install_requires=[
|
||||
'argparse',
|
||||
'plumbum',
|
||||
'pyflakes',
|
||||
'simplejson',
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:entry',
|
||||
'trailing-whitespace-fixer = pre_commit_hooks.railing_whitespace_fixer:entry',
|
||||
],
|
||||
},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue