mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
5a0366bcb0
commit
3ad7c548b7
2 changed files with 37 additions and 38 deletions
|
|
@ -282,36 +282,36 @@ class OptionalSensibleRegexAtHook(cfgv.OptionalNoDefault):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PotentiallyDangerousTrailingCharactersAtHook(cfgv.OptionalNoDefault):
|
class PotentiallyDangerousTrailingCharactersAtHook(cfgv.OptionalNoDefault):
|
||||||
def _pre_process(self, value: str) -> str:
|
def _pre_process(self, value: str) -> str:
|
||||||
"""Normalize the field value by removing tabs, newlines, spaces, and trailing )/."""
|
"""Normalize the field value by removing tabs, newlines, spaces, and trailing )/."""
|
||||||
spaces_regex_pattern = r"\s+"
|
spaces_regex_pattern = r'\s+'
|
||||||
trailing_bracket_and_slash_pattern = r"\)/$"
|
trailing_bracket_and_slash_pattern = r'\)/$'
|
||||||
combined_pattern = f"{spaces_regex_pattern}|{trailing_bracket_and_slash_pattern}"
|
combined_pattern = f"{spaces_regex_pattern}|{trailing_bracket_and_slash_pattern}"
|
||||||
return re.sub(combined_pattern, "", value.replace("\t", "").replace("\n", "").strip())
|
return re.sub(combined_pattern, '', value.replace('\t', '').replace('\n', '').strip())
|
||||||
|
|
||||||
def check(self, dct: dict[str, Any]) -> None:
|
def check(self, dct: dict[str, Any]) -> None:
|
||||||
super().check(dct)
|
super().check(dct)
|
||||||
pipe_trailing_pattern = r"\|(\)|\/)?$"
|
pipe_trailing_pattern = r'\|(\)|\/)?$'
|
||||||
slash_trailing_pattern = r"\/(\)|\/)?$"
|
slash_trailing_pattern = r'\/(\)|\/)?$'
|
||||||
|
|
||||||
pre_processed_field = self._pre_process(dct.get(self.key, ""))
|
pre_processed_field = self._pre_process(dct.get(self.key, ''))
|
||||||
|
|
||||||
if re.search(pipe_trailing_pattern, pre_processed_field):
|
if re.search(pipe_trailing_pattern, pre_processed_field):
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Potentially dangerous trailing pipe pattern detected in {self.key!r} field of the hook: {dct.get('id')!r}"
|
f"Potentially dangerous trailing pipe pattern detected in {self.key!r} field of the hook: {dct.get('id')!r}"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
)
|
)
|
||||||
|
|
||||||
if re.search(slash_trailing_pattern, pre_processed_field):
|
if re.search(slash_trailing_pattern, pre_processed_field):
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Potentially dangerous trailing slash pattern detected in {self.key!r} field of the hook: {dct.get('id')!r}"
|
f"Potentially dangerous trailing slash pattern detected in {self.key!r} field of the hook: {dct.get('id')!r}"
|
||||||
f"This can uninteded behaviour such as the files option being rendered empty"
|
f"This can uninteded behaviour such as the files option being rendered empty"
|
||||||
f"It is recommended to remove the trailing character prompted"
|
f"It is recommended to remove the trailing character prompted",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
class OptionalSensibleRegexAtTop(cfgv.OptionalNoDefault):
|
||||||
def check(self, dct: dict[str, Any]) -> None:
|
def check(self, dct: dict[str, Any]) -> None:
|
||||||
super().check(dct)
|
super().check(dct)
|
||||||
|
|
|
||||||
|
|
@ -240,63 +240,62 @@ def test_validate_optional_sensible_regex_at_hook(caplog, regex, warning):
|
||||||
assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
|
assert caplog.record_tuples == [('pre_commit', logging.WARNING, warning)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('regex', 'warning'),
|
('regex', 'warning'),
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
"(?x)^(\n^some-dir/some-sub-dir|\n)/",
|
'(?x)^(\n^some-dir/some-sub-dir|\n)/',
|
||||||
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"^some/path1|",
|
'^some/path1|',
|
||||||
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(\n" "^some/path1|\n" "^some/path2|\n" ")",
|
'(?x)^(\n' '^some/path1|\n' '^some/path2|\n' ')',
|
||||||
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"^some/path2/",
|
'^some/path2/',
|
||||||
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(^some-dir/)/",
|
'(?x)^(^some-dir/)/',
|
||||||
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(\n^some-dir|)/",
|
'(?x)^(\n^some-dir|)/',
|
||||||
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing pipe pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(\n^some-dir/\n)/",
|
'(?x)^(\n^some-dir/\n)/',
|
||||||
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(\n^some-dir/\n\t\t\t\t)/",
|
'(?x)^(\n^some-dir/\n\t\t\t\t)/',
|
||||||
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"(?x)^(\n^some-dir/\n )/",
|
'(?x)^(\n^some-dir/\n )/',
|
||||||
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
"Potentially dangerous trailing slash pattern detected in 'files' field of the hook: 'flake8'"
|
||||||
"This can uninteded behaviour such as the files option being rendered empty"
|
'This can uninteded behaviour such as the files option being rendered empty'
|
||||||
"It is recommended to remove the trailing character prompted"
|
'It is recommended to remove the trailing character prompted',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue