Skip to content

Commit

Permalink
Apply the regex validation to comma-separated regular expression opti…
Browse files Browse the repository at this point in the history
…on values.

Co-authored-by: Pierre Sassoulas <[email protected]>
  • Loading branch information
mbyrnepr2 and Pierre-Sassoulas committed Jul 31, 2022
1 parent 7c958d5 commit da09698
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pylint/config/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _regexp_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
"""Transforms a comma separated list of regular expressions."""
patterns: list[Pattern[str]] = []
for pattern in _csv_transformer(value):
patterns.append(re.compile(pattern))
patterns.append(_regex_transformer(pattern))
return patterns


Expand Down
16 changes: 16 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ def test_regex_error(capsys: CaptureFixture) -> None:
)


def test_csv_regex_error(capsys: CaptureFixture) -> None:
"""Check that we correctly error when an option is passed and one
of its comma-separated regular expressions values is an invalid regular expression.
"""
with pytest.raises(SystemExit):
Run(
[str(EMPTY_MODULE), r"--bad-names-rgx=(foo{1,3})"],
exit=False,
)
output = capsys.readouterr()
assert (
r"Error in provided regular expression: (foo{1 beginning at index 0: missing ), unterminated subpattern"
in output.err
)


def test_short_verbose(capsys: CaptureFixture) -> None:
"""Check that we correctly handle the -v flag."""
Run([str(EMPTY_MODULE), "-v"], exit=False)
Expand Down

0 comments on commit da09698

Please sign in to comment.