mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #2154 from kuviokelluja/master
fix: Add missing warning for regular expression with [\\/]
This commit is contained in:
commit
097f2c8917
2 changed files with 24 additions and 24 deletions
|
|
@ -144,18 +144,13 @@ class OptionalSensibleRegexAtHook(cfgv.OptionalNoDefault):
|
||||||
f"regex, not a glob -- matching '/*' probably isn't what you "
|
f"regex, not a glob -- matching '/*' probably isn't what you "
|
||||||
f'want here',
|
f'want here',
|
||||||
)
|
)
|
||||||
if r'[\/]' in dct.get(self.key, ''):
|
for fwd_slash_re in (r'[\\/]', r'[\/]', r'[/\\]'):
|
||||||
logger.warning(
|
if fwd_slash_re in dct.get(self.key, ''):
|
||||||
fr'pre-commit normalizes slashes in the {self.key!r} field '
|
logger.warning(
|
||||||
fr'in hook {dct.get("id")!r} to forward slashes, so you '
|
fr'pre-commit normalizes slashes in the {self.key!r} '
|
||||||
fr'can use / instead of [\/]',
|
fr'field in hook {dct.get("id")!r} to forward slashes, '
|
||||||
)
|
fr'so you can use / instead of {fwd_slash_re}',
|
||||||
if r'[/\\]' in dct.get(self.key, ''):
|
)
|
||||||
logger.warning(
|
|
||||||
fr'pre-commit normalizes slashes in the {self.key!r} field '
|
|
||||||
fr'in hook {dct.get("id")!r} to forward slashes, so you '
|
|
||||||
fr'can use / instead of [/\\]',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
||||||
|
|
@ -167,18 +162,13 @@ class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
||||||
f'The top-level {self.key!r} field is a regex, not a glob -- '
|
f'The top-level {self.key!r} field is a regex, not a glob -- '
|
||||||
f"matching '/*' probably isn't what you want here",
|
f"matching '/*' probably isn't what you want here",
|
||||||
)
|
)
|
||||||
if r'[\/]' in dct.get(self.key, ''):
|
for fwd_slash_re in (r'[\\/]', r'[\/]', r'[/\\]'):
|
||||||
logger.warning(
|
if fwd_slash_re in dct.get(self.key, ''):
|
||||||
fr'pre-commit normalizes the slashes in the top-level '
|
logger.warning(
|
||||||
fr'{self.key!r} field to forward slashes, so you can use / '
|
fr'pre-commit normalizes the slashes in the top-level '
|
||||||
fr'instead of [\/]',
|
fr'{self.key!r} field to forward slashes, so you '
|
||||||
)
|
fr'can use / instead of {fwd_slash_re}',
|
||||||
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:
|
class MigrateShaToRev:
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,11 @@ def test_warn_mutable_rev_conditional():
|
||||||
r"pre-commit normalizes slashes in the 'files' field in hook "
|
r"pre-commit normalizes slashes in the 'files' field in hook "
|
||||||
r"'flake8' to forward slashes, so you can use / instead of [/\\]",
|
r"'flake8' to forward slashes, so you can use / instead of [/\\]",
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
r'dir[\\/].*\.py',
|
||||||
|
r"pre-commit normalizes slashes in the 'files' field in hook "
|
||||||
|
r"'flake8' to forward slashes, so you can use / instead of [\\/]",
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
|
def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
|
||||||
|
|
@ -295,6 +300,11 @@ def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
|
||||||
r"pre-commit normalizes the slashes in the top-level 'files' "
|
r"pre-commit normalizes the slashes in the top-level 'files' "
|
||||||
r'field to forward slashes, so you can use / instead of [/\\]',
|
r'field to forward slashes, so you can use / instead of [/\\]',
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
r'dir[\\/].*\.py',
|
||||||
|
r"pre-commit normalizes the slashes in the top-level 'files' "
|
||||||
|
r'field to forward slashes, so you can use / instead of [\\/]',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
|
def test_validate_optional_sensible_regex_at_top_level(caplog, regex, warning):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue