From cf4cf36d4af39da18d269e2aa8554d15aeaeac24 Mon Sep 17 00:00:00 2001 From: Radek SPRTA Date: Tue, 21 Sep 2021 20:57:56 +0200 Subject: [PATCH] Check for [/\\] in OptionalSensibleRegexAt* as well --- pre_commit/clientlib.py | 12 ++++++++++++ tests/clientlib_test.py | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/pre_commit/clientlib.py b/pre_commit/clientlib.py index f0a92810a..86b517cce 100644 --- a/pre_commit/clientlib.py +++ b/pre_commit/clientlib.py @@ -149,6 +149,12 @@ def check(self, dct: Dict[str, Any]) -> None: fr"hook {dct.get('id')!r} to forward slashes, so you can use " fr'/ instead of [\/]', ) + if r'[/\\]' in dct.get(self.key, ''): + logger.warning( + fr'pre-commit normalizes the slashes in {self.key!r} field in ' + fr"hook {dct.get('id')!r} to forward slashes, so you can use " + fr'/ instead of [/\\]', + ) class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault): @@ -166,6 +172,12 @@ def check(self, dct: Dict[str, Any]) -> None: fr'{self.key!r} field to forward slashes, so you can use / ' fr'instead of [\/]', ) + if r'[/\\]' in dct.get(self.key, ''): + logger.warning( + fr'pre-commit normalizes the slashes in the top-level ' + fr'{self.key!r} field to forward slashes, so you can use / ' + fr'instead of [/\\]', + ) class MigrateShaToRev: diff --git a/tests/clientlib_test.py b/tests/clientlib_test.py index f354c3cb3..454b167e7 100644 --- a/tests/clientlib_test.py +++ b/tests/clientlib_test.py @@ -260,6 +260,11 @@ def test_warn_mutable_rev_conditional(): r"pre-commit normalizes the slashes in 'files' field in hook " r"'flake8' to forward slashes, so you can use / instead of [\/]", ), + ( + r'dir[/\\].*\.py', + r"pre-commit normalizes the slashes in 'files' field in hook " + r"'flake8' to forward slashes, so you can use / instead of [/\\]", + ), ], ) def test_validate_optional_sensible_regex_at_hook_level(caplog, regex, warning): @@ -285,6 +290,11 @@ def test_validate_optional_sensible_regex_at_hook_level(caplog, regex, warning): r"pre-commit normalizes the slashes in the top-level 'files' field " r'to forward slashes, so you can use / instead of [\/]', ), + ( + r'dir[/\\].*\.py', + r"pre-commit normalizes the slashes in the top-level 'files' field " + r'to forward slashes, so you can use / instead of [/\\]', + ), ], ) def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):