mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Implement check-useless-excludes meta hook
This commit is contained in:
parent
88c676a7c1
commit
8df11ee7aa
4 changed files with 118 additions and 8 deletions
|
|
@ -653,7 +653,7 @@ def test_meta_hook_passes(
|
|||
(
|
||||
'hooks', (
|
||||
OrderedDict((
|
||||
('id', 'test-hook'),
|
||||
('id', 'check-useless-excludes'),
|
||||
)),
|
||||
),
|
||||
),
|
||||
|
|
@ -663,13 +663,78 @@ def test_meta_hook_passes(
|
|||
_test_run(
|
||||
cap_out,
|
||||
repo_with_passing_hook,
|
||||
opts={'verbose': True},
|
||||
expected_outputs=[b'Hello World!'],
|
||||
opts={},
|
||||
expected_outputs=[b'Check for useless excludes'],
|
||||
expected_ret=0,
|
||||
stage=False,
|
||||
)
|
||||
|
||||
|
||||
def test_useless_exclude_global(
|
||||
cap_out, repo_with_passing_hook, mock_out_store_directory,
|
||||
):
|
||||
config = OrderedDict((
|
||||
('exclude', 'foo'),
|
||||
(
|
||||
'repos', [
|
||||
OrderedDict((
|
||||
('repo', 'meta'),
|
||||
(
|
||||
'hooks', (
|
||||
OrderedDict((
|
||||
('id', 'check-useless-excludes'),
|
||||
)),
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
))
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
_test_run(
|
||||
cap_out,
|
||||
repo_with_passing_hook,
|
||||
opts={'all_files': True},
|
||||
expected_outputs=[
|
||||
b'Check for useless excludes',
|
||||
b'The global exclude pattern does not match any files',
|
||||
],
|
||||
expected_ret=1,
|
||||
stage=False,
|
||||
)
|
||||
|
||||
|
||||
def test_useless_exclude_for_hook(
|
||||
cap_out, repo_with_passing_hook, mock_out_store_directory,
|
||||
):
|
||||
config = OrderedDict((
|
||||
('repo', 'meta'),
|
||||
(
|
||||
'hooks', (
|
||||
OrderedDict((
|
||||
('id', 'check-useless-excludes'),
|
||||
('exclude', 'foo'),
|
||||
)),
|
||||
),
|
||||
),
|
||||
))
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
_test_run(
|
||||
cap_out,
|
||||
repo_with_passing_hook,
|
||||
opts={'all_files': True},
|
||||
expected_outputs=[
|
||||
b'Check for useless excludes',
|
||||
b'The exclude pattern for check-useless-excludes '
|
||||
b'does not match any files',
|
||||
],
|
||||
expected_ret=1,
|
||||
stage=False,
|
||||
)
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def modified_config_repo(repo_with_passing_hook):
|
||||
with modify_config(repo_with_passing_hook, commit=False) as config:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue