mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Remove unnecessary object level at top of manifest
This commit is contained in:
parent
af7e23aae5
commit
e5f4c61608
4 changed files with 54 additions and 66 deletions
|
|
@ -1,31 +1,29 @@
|
||||||
|
|
||||||
# Hooks are set up as follows
|
# Hooks are set up as follows
|
||||||
# hooks:
|
# -
|
||||||
# -
|
# id: hook_id
|
||||||
# id: hook_id
|
# name: 'Readable name'
|
||||||
# name: 'Readable name'
|
# entry: my_hook_executable
|
||||||
# entry: my_hook_executable
|
|
||||||
#
|
#
|
||||||
# # Optional
|
# # Optional
|
||||||
# description: 'Longer description of the hook'
|
# description: 'Longer description of the hook'
|
||||||
#
|
#
|
||||||
# # Optional, for now 'python[optional version]', 'ruby #.#.#', 'node'
|
# # Optional, for now 'python[optional version]', 'ruby #.#.#', 'node'
|
||||||
# language: 'python'
|
# language: 'python'
|
||||||
#
|
#
|
||||||
# # Optional, defaults to zero
|
# # Optional, defaults to zero
|
||||||
# expected_return_value: 0
|
# expected_return_value: 0
|
||||||
|
|
||||||
hooks:
|
-
|
||||||
-
|
id: my_hook
|
||||||
id: my_hook
|
name: My Simple Hook
|
||||||
name: My Simple Hook
|
description: This is my simple hook that does blah
|
||||||
description: This is my simple hook that does blah
|
entry: my-simple-hook.py
|
||||||
entry: my-simple-hook.py
|
language: python
|
||||||
language: python
|
expected_return_value: 0
|
||||||
expected_return_value: 0
|
-
|
||||||
-
|
id: my_grep_based_hook
|
||||||
id: my_grep_based_hook
|
name: My Bash Based Hook
|
||||||
name: My Bash Based Hook
|
description: This is a hook that uses grep to validate some stuff
|
||||||
description: This is a hook that uses grep to validate some stuff
|
entry: ./my_grep_based_hook.sh
|
||||||
entry: ./my_grep_based_hook.sh
|
expected_return_value: 1
|
||||||
expected_return_value: 1
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
hooks:
|
-
|
||||||
-
|
id: validate_manifest
|
||||||
id: validate_manifest
|
name: Validate Manifest
|
||||||
name: Validate Manifest
|
description: This validator validates a pre-commit hooks manifest file
|
||||||
description: This validator validates a pre-commit hooks manifest file
|
entry: validate-manifest
|
||||||
entry: validate-manifest
|
language: python
|
||||||
language: python
|
|
||||||
|
|
@ -11,31 +11,25 @@ class InvalidManifestError(ValueError): pass
|
||||||
|
|
||||||
|
|
||||||
MANIFEST_JSON_SCHEMA = {
|
MANIFEST_JSON_SCHEMA = {
|
||||||
'type': 'object',
|
'type': 'array',
|
||||||
'properties': {
|
'minItems': 1,
|
||||||
'hooks': {
|
'items': {
|
||||||
'type': 'array',
|
'type': 'object',
|
||||||
'minItems': 1,
|
'properties': {
|
||||||
'items': {
|
'id': {'type': 'string'},
|
||||||
'type': 'object',
|
'name': {'type': 'string'},
|
||||||
'properties': {
|
'description': {'type': 'string'},
|
||||||
'id': {'type': 'string'},
|
'entry': {'type': 'string'},
|
||||||
'name': {'type': 'string'},
|
'language': {'type': 'string'},
|
||||||
'description': {'type': 'string'},
|
'expected_return_value': {'type': 'number'},
|
||||||
'entry': {'type': 'string'},
|
|
||||||
'language': {'type': 'string'},
|
|
||||||
'expected_return_value': {'type': 'number'},
|
|
||||||
},
|
|
||||||
'required': ['id', 'name', 'entry'],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
'required': ['id', 'name', 'entry'],
|
||||||
},
|
},
|
||||||
'required': ['hooks'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def additional_manifest_check(obj):
|
def additional_manifest_check(obj):
|
||||||
for hook_config in obj['hooks']:
|
for hook_config in obj:
|
||||||
language = hook_config.get('language')
|
language = hook_config.get('language')
|
||||||
|
|
||||||
if language is not None and not any(
|
if language is not None and not any(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ def print_mock():
|
||||||
|
|
||||||
def test_run_returns_1_for_non_existent_module(print_mock):
|
def test_run_returns_1_for_non_existent_module(print_mock):
|
||||||
non_existent_filename = 'file_that_does_not_exist'
|
non_existent_filename = 'file_that_does_not_exist'
|
||||||
ret = run(['--filename', non_existent_filename])
|
ret = run([non_existent_filename])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
print_mock.assert_called_once_with(
|
print_mock.assert_called_once_with(
|
||||||
'File {0} does not exist'.format(non_existent_filename),
|
'File {0} does not exist'.format(non_existent_filename),
|
||||||
|
|
@ -26,7 +26,7 @@ def test_run_returns_1_for_non_existent_module(print_mock):
|
||||||
|
|
||||||
def test_run_returns_1_for_non_yaml_file(print_mock):
|
def test_run_returns_1_for_non_yaml_file(print_mock):
|
||||||
non_parseable_filename = 'tests/data/non_parseable_yaml_file.yaml'
|
non_parseable_filename = 'tests/data/non_parseable_yaml_file.yaml'
|
||||||
ret = run(['--filename', non_parseable_filename])
|
ret = run([non_parseable_filename])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
print_mock.assert_any_call(
|
print_mock.assert_any_call(
|
||||||
'File {0} is not a valid yaml file'.format(non_parseable_filename),
|
'File {0} is not a valid yaml file'.format(non_parseable_filename),
|
||||||
|
|
@ -35,7 +35,7 @@ def test_run_returns_1_for_non_yaml_file(print_mock):
|
||||||
|
|
||||||
def test_returns_1_for_valid_yaml_file_but_invalid_manifest(print_mock):
|
def test_returns_1_for_valid_yaml_file_but_invalid_manifest(print_mock):
|
||||||
invalid_manifest = 'tests/data/valid_yaml_but_invalid_manifest.yaml'
|
invalid_manifest = 'tests/data/valid_yaml_but_invalid_manifest.yaml'
|
||||||
ret = run(['--filename', invalid_manifest])
|
ret = run([invalid_manifest])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
print_mock.assert_any_call(
|
print_mock.assert_any_call(
|
||||||
'File {0} is not a valid file'.format(invalid_manifest)
|
'File {0} is not a valid file'.format(invalid_manifest)
|
||||||
|
|
@ -44,17 +44,16 @@ def test_returns_1_for_valid_yaml_file_but_invalid_manifest(print_mock):
|
||||||
|
|
||||||
def test_returns_0_for_valid_manifest():
|
def test_returns_0_for_valid_manifest():
|
||||||
valid_manifest = 'example_manifest.yaml'
|
valid_manifest = 'example_manifest.yaml'
|
||||||
ret = run(['--filename', valid_manifest])
|
ret = run([valid_manifest])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
|
||||||
def test_uses_default_manifest_file_at_root_of_git(empty_git_dir):
|
def test_uses_default_manifest_file_at_root_of_git(empty_git_dir):
|
||||||
local.path(C.MANIFEST_FILE).write("""
|
local.path(C.MANIFEST_FILE).write("""
|
||||||
hooks:
|
-
|
||||||
-
|
id: foo
|
||||||
id: foo
|
name: Foo
|
||||||
name: Foo
|
entry: foo
|
||||||
entry: foo
|
|
||||||
""")
|
""")
|
||||||
ret = run([])
|
ret = run([])
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
@ -62,15 +61,13 @@ hooks:
|
||||||
|
|
||||||
def test_additional_manifest_check_raises_for_bad_language():
|
def test_additional_manifest_check_raises_for_bad_language():
|
||||||
with pytest.raises(InvalidManifestError):
|
with pytest.raises(InvalidManifestError):
|
||||||
additional_manifest_check(
|
additional_manifest_check([{'id': 'foo', 'language': 'not valid'}])
|
||||||
{'hooks': [{'id': 'foo', 'language': 'not valid'}]}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('obj'), (
|
@pytest.mark.parametrize(('obj'), (
|
||||||
{'hooks': [{}]},
|
[{}],
|
||||||
{'hooks': [{'language': 'python'}]},
|
[{'language': 'python'}],
|
||||||
{'hooks': [{'language': 'python>2.6'}]},
|
[{'language': 'python>2.6'}],
|
||||||
))
|
))
|
||||||
def test_additional_manifest_check_is_ok_with_missing_language(obj):
|
def test_additional_manifest_check_is_ok_with_missing_language(obj):
|
||||||
additional_manifest_check(obj)
|
additional_manifest_check(obj)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue