mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 20:26:54 +00:00
Add trailing whitespace fixer.
This commit is contained in:
parent
10c042c99c
commit
acd9eaf6ed
6 changed files with 44 additions and 2 deletions
|
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
-
|
-
|
||||||
repo: git@github.com:pre-commit/pre-commit-hooks
|
repo: git@github.com:pre-commit/pre-commit-hooks
|
||||||
sha: 5e713f8878b7d100c0e059f8cc34be4fc2e8f897
|
sha: 10c042c99c061b90e4ea11d52e3c5fc93f94b373
|
||||||
hooks:
|
hooks:
|
||||||
-
|
-
|
||||||
id: pyflakes
|
id: pyflakes
|
||||||
files: '\.py$'
|
files: '\.py$'
|
||||||
|
-
|
||||||
|
id: debug-statements
|
||||||
|
files: '\.py$'
|
||||||
|
|
||||||
-
|
-
|
||||||
repo: git@github.com:pre-commit/pre-commit
|
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.
|
description: This hook checks that debug statements (pdb, ipdb, pudb) are not imported on commit.
|
||||||
entry: debug-statement-hook
|
entry: debug-statement-hook
|
||||||
language: python
|
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):
|
def debug_statement_hook(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
parser.add_argument('filenames', nargs='*', help='Filenames to run')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
retv = 0
|
retv = 0
|
||||||
for filename in args.filenames:
|
for filename in args.filenames:
|
||||||
|
|
|
||||||
30
pre_commit_hooks/trailing_whitespace_fixer.py
Normal file
30
pre_commit_hooks/trailing_whitespace_fixer.py
Normal file
|
|
@ -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
|
argparse
|
||||||
|
plumbum
|
||||||
pyflakes
|
pyflakes
|
||||||
simplejson
|
simplejson
|
||||||
|
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -7,12 +7,14 @@ setup(
|
||||||
packages=find_packages('.', exclude=('tests*', 'testing*')),
|
packages=find_packages('.', exclude=('tests*', 'testing*')),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'argparse',
|
'argparse',
|
||||||
|
'plumbum',
|
||||||
'pyflakes',
|
'pyflakes',
|
||||||
'simplejson',
|
'simplejson',
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:entry',
|
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:entry',
|
||||||
|
'trailing-whitespace-fixer = pre_commit_hooks.railing_whitespace_fixer:entry',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue