Skip to content

Commit

Permalink
Check for [/\\] in OptionalSensibleRegexAt* as well
Browse files Browse the repository at this point in the history
  • Loading branch information
radek-sprta committed Sep 21, 2021
1 parent 00a1aac commit cf4cf36
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pre_commit/clientlib.py
Expand Up @@ -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):
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/clientlib_test.py
Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit cf4cf36

Please sign in to comment.