Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pre_commit/clientlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ def remove_default(self, dct: dict[str, Any]) -> None:
raise NotImplementedError


class DeprecatedDefaultStagesWarning(NamedTuple):
key: str

def check(self, dct: dict[str, Any]) -> None:
if self.key not in dct:
return

val = dct[self.key]
cfgv.check_array(cfgv.check_any)(val)

legacy_stages = [stage for stage in val if stage in _STAGES]
if legacy_stages:
logger.warning(
f'top-level `default_stages` uses deprecated stage names '
f'({", ".join(legacy_stages)}) which will be removed in a '
f'future version. '
f'run: `pre-commit migrate-config` to automatically fix this.',
)

def apply_default(self, dct: dict[str, Any]) -> None:
pass

def remove_default(self, dct: dict[str, Any]) -> None:
raise NotImplementedError


MANIFEST_HOOK_DICT = cfgv.Map(
'Hook', 'id',

Expand Down Expand Up @@ -398,6 +424,7 @@ def check(self, dct: dict[str, Any]) -> None:
'default_language_version', DEFAULT_LANGUAGE_VERSION, {},
),
StagesMigration('default_stages', STAGES),
DeprecatedDefaultStagesWarning('default_stages'),
cfgv.Optional('files', check_string_regex, ''),
cfgv.Optional('exclude', check_string_regex, '^$'),
cfgv.Optional('fail_fast', cfgv.check_bool, False),
Expand Down
24 changes: 24 additions & 0 deletions tests/clientlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ def test_no_warning_for_non_deprecated_stages(caplog):
assert caplog.record_tuples == []


def test_warning_for_deprecated_default_stages(caplog):
cfg = {'default_stages': ['commit', 'push'], 'repos': []}

cfgv.validate(cfg, CONFIG_SCHEMA)

assert caplog.record_tuples == [
(
'pre_commit',
logging.WARNING,
'top-level `default_stages` uses deprecated stage names '
'(commit, push) which will be removed in a future version. '
'run: `pre-commit migrate-config` to automatically fix this.',
),
]


def test_no_warning_for_non_deprecated_default_stages(caplog):
cfg = {'default_stages': ['pre-commit', 'pre-push'], 'repos': []}

cfgv.validate(cfg, CONFIG_SCHEMA)

assert caplog.record_tuples == []


@pytest.mark.parametrize(
'manifest_obj',
(
Expand Down