mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 20:16:53 +00:00
commit
d0adff17ba
8 changed files with 59 additions and 5 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
- repo: git@github.com:pre-commit/pre-commit-hooks
|
- repo: git@github.com:pre-commit/pre-commit-hooks
|
||||||
sha: ba52312ee8a95ca1b075ee864f3ab78bd5f592a4
|
sha: 243fe50bc119bc5f72be76fc4e3de260ee6f64f1
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
|
- id: check-json
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: debug-statements
|
- id: debug-statements
|
||||||
- id: name-tests-test
|
- id: name-tests-test
|
||||||
|
|
|
||||||
10
hooks.yaml
10
hooks.yaml
|
|
@ -1,3 +1,9 @@
|
||||||
|
- id: check-json
|
||||||
|
name: Check JSON
|
||||||
|
description: This hook checks json files for parseable syntax.
|
||||||
|
entry: check-json
|
||||||
|
language: python
|
||||||
|
files: \.json$
|
||||||
- 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.
|
||||||
|
|
@ -15,7 +21,7 @@
|
||||||
description: Ensures that a file is either empty, or ends with one newline.
|
description: Ensures that a file is either empty, or ends with one newline.
|
||||||
entry: end-of-file-fixer
|
entry: end-of-file-fixer
|
||||||
language: python
|
language: python
|
||||||
files: \.(js|rb|md|py|scss|sh|tmpl|txt|yaml|yml)$
|
files: \.(js|json|rb|md|py|scss|sh|tmpl|txt|yaml|yml)$
|
||||||
- id: flake8
|
- id: flake8
|
||||||
name: Flake8
|
name: Flake8
|
||||||
description: This hook runs flake8.
|
description: This hook runs flake8.
|
||||||
|
|
@ -39,4 +45,4 @@
|
||||||
description: This hook trims trailing whitespace.
|
description: This hook trims trailing whitespace.
|
||||||
entry: trailing-whitespace-fixer
|
entry: trailing-whitespace-fixer
|
||||||
language: python
|
language: python
|
||||||
files: \.(js|rb|md|py|scss|sh|tmpl|txt|yaml|yml)$
|
files: \.(js|json|rb|md|py|scss|sh|tmpl|txt|yaml|yml)$
|
||||||
|
|
|
||||||
27
pre_commit_hooks/check_json.py
Normal file
27
pre_commit_hooks/check_json.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import simplejson
|
||||||
|
|
||||||
|
from pre_commit_hooks.util import entry
|
||||||
|
|
||||||
|
|
||||||
|
@entry
|
||||||
|
def check_json(argv):
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('filenames', nargs='*', help='JSON filenames to check.')
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
retval = 0
|
||||||
|
for filename in args.filenames:
|
||||||
|
try:
|
||||||
|
simplejson.load(open(filename))
|
||||||
|
except simplejson.JSONDecodeError as e:
|
||||||
|
print('{0}: Failed to json encode ({1})'.format(filename, e))
|
||||||
|
retval = 1
|
||||||
|
return retval
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(check_json())
|
||||||
|
|
@ -10,7 +10,7 @@ from pre_commit_hooks.util import entry
|
||||||
@entry
|
@entry
|
||||||
def check_yaml(argv):
|
def check_yaml(argv):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
parser.add_argument('filenames', nargs='*', help='Yaml filenames to check.')
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
retval = 0
|
retval = 0
|
||||||
|
|
|
||||||
3
setup.py
3
setup.py
|
|
@ -6,7 +6,7 @@ setup(
|
||||||
name='pre_commit_hooks',
|
name='pre_commit_hooks',
|
||||||
description='Some out-of-the-box hooks for pre-commit.',
|
description='Some out-of-the-box hooks for pre-commit.',
|
||||||
url='https://github.com/pre-commit/pre-commit-hooks',
|
url='https://github.com/pre-commit/pre-commit-hooks',
|
||||||
version='0.1.1',
|
version='0.2.0',
|
||||||
|
|
||||||
author='Anthony Sottile',
|
author='Anthony Sottile',
|
||||||
author_email='asottile@umich.edu',
|
author_email='asottile@umich.edu',
|
||||||
|
|
@ -32,6 +32,7 @@ setup(
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
'check-json = pre_commit_hooks.check_json:check_json',
|
||||||
'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',
|
||||||
|
|
|
||||||
3
testing/resources/bad_json.notjson
Normal file
3
testing/resources/bad_json.notjson
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"hello": "world",
|
||||||
|
}
|
||||||
3
testing/resources/ok_json.json
Normal file
3
testing/resources/ok_json.json
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"hello": "world"
|
||||||
|
}
|
||||||
13
tests/check_json_test.py
Normal file
13
tests/check_json_test.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from pre_commit_hooks.check_json import check_json
|
||||||
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||||
|
('bad_json.notjson', 1),
|
||||||
|
('ok_json.json', 0),
|
||||||
|
))
|
||||||
|
def test_check_json(filename, expected_retval):
|
||||||
|
ret = check_json([get_resource_path(filename)])
|
||||||
|
assert ret == expected_retval
|
||||||
Loading…
Add table
Add a link
Reference in a new issue