mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-10 05:14:18 +00:00
commit
144e6a931e
10 changed files with 57 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ env: # These should match the tox env list
|
||||||
- TOXENV=py33
|
- TOXENV=py33
|
||||||
- TOXENV=py34
|
- TOXENV=py34
|
||||||
- TOXENV=pypy
|
- TOXENV=pypy
|
||||||
|
- TOXENV=pypy3
|
||||||
install: pip install coveralls tox --use-mirrors
|
install: pip install coveralls tox --use-mirrors
|
||||||
script: tox
|
script: tox
|
||||||
# Special snowflake. Our tests depend on making real commits.
|
# Special snowflake. Our tests depend on making real commits.
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ Add this to your `.pre-commit-config.yaml`
|
||||||
- `check-case-conflict` - Check for files that would conflict in case-insensitive filesystems.
|
- `check-case-conflict` - Check for files that would conflict in case-insensitive filesystems.
|
||||||
- `check-docstring-first` - Checks a common error of defining a docstring after code.
|
- `check-docstring-first` - Checks a common error of defining a docstring after code.
|
||||||
- `check-json` - Attempts to load all json files to verify syntax.
|
- `check-json` - Attempts to load all json files to verify syntax.
|
||||||
|
- `check-xml` - Attempts to load all xml files to verify syntax.
|
||||||
- `check-yaml` - Attempts to load all yaml files to verify syntax.
|
- `check-yaml` - Attempts to load all yaml files to verify syntax.
|
||||||
- `debug-statements` - Check for pdb / ipdb / pudb statements in code.
|
- `debug-statements` - Check for pdb / ipdb / pudb statements in code.
|
||||||
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
|
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@
|
||||||
entry: check-json
|
entry: check-json
|
||||||
language: python
|
language: python
|
||||||
files: \.json$
|
files: \.json$
|
||||||
|
- id: check-xml
|
||||||
|
name: Check Xml
|
||||||
|
description: This hook checks xml files for parseable syntax.
|
||||||
|
entry: check-xml
|
||||||
|
language: python
|
||||||
|
files: \.xml$
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
name: Check Yaml
|
name: Check Yaml
|
||||||
description: This hook checks yaml files for parseable syntax.
|
description: This hook checks yaml files for parseable syntax.
|
||||||
|
|
|
||||||
28
pre_commit_hooks/check_xml.py
Normal file
28
pre_commit_hooks/check_xml.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import io
|
||||||
|
import sys
|
||||||
|
import xml.sax
|
||||||
|
|
||||||
|
|
||||||
|
def check_xml(argv=None):
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('filenames', nargs='*', help='XML filenames to check.')
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
retval = 0
|
||||||
|
for filename in args.filenames:
|
||||||
|
try:
|
||||||
|
with io.open(filename, 'rb') as xml_file:
|
||||||
|
xml.sax.parse(xml_file, xml.sax.ContentHandler())
|
||||||
|
except xml.sax.SAXException as exc:
|
||||||
|
print('{0}: Failed to xml parse ({1})'.format(filename, exc))
|
||||||
|
retval = 1
|
||||||
|
return retval
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(check_xml())
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
-e .
|
-e .
|
||||||
|
|
||||||
|
astroid<1.3.3
|
||||||
coverage
|
coverage
|
||||||
flake8
|
flake8
|
||||||
mock
|
mock
|
||||||
|
|
|
||||||
1
setup.py
1
setup.py
|
|
@ -41,6 +41,7 @@ setup(
|
||||||
'check-case-conflict = pre_commit_hooks.check_case_conflict:main',
|
'check-case-conflict = pre_commit_hooks.check_case_conflict:main',
|
||||||
'check-docstring-first = pre_commit_hooks.check_docstring_first:main',
|
'check-docstring-first = pre_commit_hooks.check_docstring_first:main',
|
||||||
'check-json = pre_commit_hooks.check_json:check_json',
|
'check-json = pre_commit_hooks.check_json:check_json',
|
||||||
|
'check-xml = pre_commit_hooks.check_xml:check_xml',
|
||||||
'check-yaml = pre_commit_hooks.check_yaml:check_yaml',
|
'check-yaml = pre_commit_hooks.check_yaml:check_yaml',
|
||||||
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:debug_statement_hook',
|
'debug-statement-hook = pre_commit_hooks.debug_statement_hook:debug_statement_hook',
|
||||||
'end-of-file-fixer = pre_commit_hooks.end_of_file_fixer:end_of_file_fixer',
|
'end-of-file-fixer = pre_commit_hooks.end_of_file_fixer:end_of_file_fixer',
|
||||||
|
|
|
||||||
1
testing/resources/bad_xml.notxml
Normal file
1
testing/resources/bad_xml.notxml
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<im><not><terminated><lol>
|
||||||
4
testing/resources/ok_xml.xml
Normal file
4
testing/resources/ok_xml.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
<document>
|
||||||
|
<hello>Hi</hello>
|
||||||
|
<world>Earth</world>
|
||||||
|
</document>
|
||||||
13
tests/check_xml_test.py
Normal file
13
tests/check_xml_test.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit_hooks.check_xml import check_xml
|
||||||
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||||
|
('bad_xml.notxml', 1),
|
||||||
|
('ok_xml.xml', 0),
|
||||||
|
))
|
||||||
|
def test_check_xml(filename, expected_retval):
|
||||||
|
ret = check_xml([get_resource_path(filename)])
|
||||||
|
assert ret == expected_retval
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -1,7 +1,7 @@
|
||||||
[tox]
|
[tox]
|
||||||
project = pre_commit_hooks
|
project = pre_commit_hooks
|
||||||
# These should match the travis env list
|
# These should match the travis env list
|
||||||
envlist = py26,py27,py33,py34,pypy
|
envlist = py26,py27,py33,py34,pypy,pypy3
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
install_command = pip install --use-wheel {opts} {packages}
|
install_command = pip install --use-wheel {opts} {packages}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue