Skip to content

Commit

Permalink
Gracefully handle invalid paths csv regex in conf/args
Browse files Browse the repository at this point in the history
Fix 'ignore-paths', in particular, but others using this function too.

Closes #9680

(cherry picked from commit 3f1f7b8)
  • Loading branch information
Pierre-Sassoulas authored and github-actions[bot] committed Jun 8, 2024
1 parent c3e2579 commit 37e9772
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/9680.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Impossible to compile regexes for paths in the configuration or argument given to pylint won't crash anymore but
raise an argparse error and display the error message from ``re.compile`` instead.

Closes #9680
4 changes: 2 additions & 2 deletions pylint/config/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _py_version_transformer(value: str) -> tuple[int, ...]:


def _regex_transformer(value: str) -> Pattern[str]:
"""Return `re.compile(value)`."""
"""Prevents 're.error' from propagating and crash pylint."""
try:
return re.compile(value)
except re.error as e:
Expand All @@ -124,7 +124,7 @@ def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
patterns: list[Pattern[str]] = []
for pattern in _csv_transformer(value):
patterns.append(
re.compile(
_regex_transformer(
str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
+ "|"
+ pathlib.PureWindowsPath(pattern).as_posix()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usage: pylint [options]
pylint: error: argument --ignore-paths: Error in provided regular expression: project\\tooling_context\\**|project/tooling_context/** beginning at index 27: multiple repeat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that we report regex error in configuration file properly
[tool.pylint."main"]
ignore-paths = ['project/tooling_context/**']

0 comments on commit 37e9772

Please sign in to comment.