From ce25b652b91966b0dfb528299f8f1f84a3893192 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 2 Sep 2018 18:54:34 -0700 Subject: [PATCH] Exempt `language: fail` hooks from check-hooks-apply --- pre_commit/meta_hooks/check_hooks_apply.py | 2 +- tests/meta_hooks/check_hooks_apply_test.py | 31 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pre_commit/meta_hooks/check_hooks_apply.py b/pre_commit/meta_hooks/check_hooks_apply.py index 23420f46..4c4719c8 100644 --- a/pre_commit/meta_hooks/check_hooks_apply.py +++ b/pre_commit/meta_hooks/check_hooks_apply.py @@ -15,7 +15,7 @@ def check_all_hooks_match_files(config_file): for repo in repositories(load_config(config_file), Store()): for hook_id, hook in repo.hooks: - if hook['always_run']: + if hook['always_run'] or hook['language'] == 'fail': continue include, exclude = hook['files'], hook['exclude'] filtered = _filter_by_include_exclude(files, include, exclude) diff --git a/tests/meta_hooks/check_hooks_apply_test.py b/tests/meta_hooks/check_hooks_apply_test.py index e6a7b133..c75b036a 100644 --- a/tests/meta_hooks/check_hooks_apply_test.py +++ b/tests/meta_hooks/check_hooks_apply_test.py @@ -106,7 +106,7 @@ def test_hook_types_excludes_everything( assert 'check-useless-excludes does not apply to this repository' in out -def test_valid_includes(capsys, tempdir_factory, mock_store_dir): +def test_valid_always_run(capsys, tempdir_factory, mock_store_dir): config = { 'repos': [ { @@ -131,3 +131,32 @@ def test_valid_includes(capsys, tempdir_factory, mock_store_dir): out, _ = capsys.readouterr() assert out == '' + + +def test_valid_language_fail(capsys, tempdir_factory, mock_store_dir): + config = { + 'repos': [ + { + 'repo': 'local', + 'hooks': [ + # Should not be reported as an error due to language: fail + { + 'id': 'changelogs-rst', + 'name': 'changelogs must be rst', + 'entry': 'changelog filenames must end in .rst', + 'language': 'fail', + 'files': r'changelog/.*(?