File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 33
44import argparse
55import functools
6+ import logging
67import pipes
78import sys
89
1516from pre_commit .languages .all import all_languages
1617from pre_commit .util import parse_version
1718
19+ logger = logging .getLogger ('pre_commit' )
20+
1821
1922def check_type_tag (tag ):
2023 if tag not in ALL_TAGS :
@@ -144,6 +147,16 @@ def _entry(modname):
144147 )
145148
146149
150+ def warn_on_unknown_keys_at_top_level (extra , orig_keys ):
151+ logger .warning (
152+ 'Your pre-commit-config contain these extra keys: {}. '
153+ 'while the only valid keys are: {}.' .format (
154+ ', ' .join (extra ),
155+ ', ' .join (sorted (orig_keys )),
156+ ),
157+ ),
158+
159+
147160_meta = (
148161 (
149162 'check-hooks-apply' , (
@@ -222,6 +235,10 @@ def _entry(modname):
222235 ),
223236
224237 MigrateShaToRev (),
238+ cfgv .WarnAdditionalKeys (
239+ {'repo' , 'rev' , 'hooks' },
240+ warn_on_unknown_keys_at_top_level ,
241+ ),
225242)
226243DEFAULT_LANGUAGE_VERSION = cfgv .Map (
227244 'DefaultLanguageVersion' , None ,
Original file line number Diff line number Diff line change 11from __future__ import unicode_literals
22
3+ import logging
4+
35import cfgv
46import pytest
57
@@ -116,6 +118,27 @@ def test_validate_config_old_list_format_ok(tmpdir):
116118 assert not validate_config_main ((f .strpath ,))
117119
118120
121+ def test_validate_warn_on_unknown_keys_at_top_level (tmpdir , caplog ):
122+ f = tmpdir .join ('cfg.yaml' )
123+ f .write (
124+ '- repo: https://gitlab.com/pycqa/flake8\n '
125+ ' rev: 3.7.7\n '
126+ ' hooks:\n '
127+ ' - id: flake8\n '
128+ ' args: [--some-args]\n ' ,
129+ )
130+ ret_val = validate_config_main ((f .strpath ,))
131+ assert not ret_val
132+ assert caplog .record_tuples == [
133+ (
134+ 'pre_commit' ,
135+ logging .WARNING ,
136+ 'Your pre-commit-config contain these extra keys: args. '
137+ 'while the only valid keys are: hooks, repo, rev.' ,
138+ ),
139+ ]
140+
141+
119142@pytest .mark .parametrize ('fn' , (validate_config_main , validate_manifest_main ))
120143def test_mains_not_ok (tmpdir , fn ):
121144 not_yaml = tmpdir .join ('f.notyaml' )
You can’t perform that action at this time.
0 commit comments