Skip to content

--ignore-paths and escaping of regex special characters #7094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stanislavlevin opened this issue Jun 30, 2022 · 1 comment
Closed

--ignore-paths and escaping of regex special characters #7094

stanislavlevin opened this issue Jun 30, 2022 · 1 comment
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@stanislavlevin
Copy link
Contributor

Bug description

It's impossible to escape special regex characters in option --ignore-paths for unix paths.

The basic example is how to escape the dot (.).

(pylint) [builder@localhost test]$ python -m pylint --recursive=y --ignore-paths='^\.tox/.*' .
> /usr/src/pyproject_installer/.tox/pylint/lib/python3/site-packages/pylint/config/argument.py(115)_regexp_paths_csv_transfomer()
-> patterns.append(
(Pdb) pattern
'^\\.tox/.*'
(Pdb) l
110     def _regexp_paths_csv_transfomer(value: str) -> Sequence[Pattern[str]]:
111         """Transforms a comma separated list of regular expressions paths."""
112         patterns: list[Pattern[str]] = []
113         breakpoint()
114         for pattern in _csv_transformer(value):
115  ->         patterns.append(
116                 re.compile(
117                     str(pathlib.PureWindowsPath(pattern)).replace("\\", "\\\\")
118                     + "|"
119                     + pathlib.PureWindowsPath(pattern).as_posix()
120                 )
(Pdb) pathlib.PureWindowsPath(pattern).as_posix()
'^/.tox/.*'
(Pdb) pathlib.PureWindowsPath(pattern)
PureWindowsPath('^/.tox/.*')

Thereby, assumption regex pattern => PureWindowsPath => regex pattern is wrong and who knows where it will shoot.

Configuration

No response

Command used

mkdir .tox && echo 'import bar' > .tox/foo.py
python -m pylint --recursive=y --ignore-paths='^\.tox/.*' .

Pylint output

(pylint) [builder@localhost test]$ python -m pylint --recursive=y --ignore-paths='^\.tox/.*' .
************* Module foo
.tox/foo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
.tox/foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
.tox/foo.py:1:0: E0401: Unable to import 'bar' (import-error)
.tox/foo.py:1:0: W0611: Unused import bar (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

According to documentation:

--ignore-paths
Add files or directories matching the regex patterns to the ignore-list. The regex matches against paths and can be in Posix or Windows format.

Actually used regex should conform to the passed one and content of .tox should be ignored.
Note: it works if the escaping is dropped:
python -m pylint --recursive=y --ignore-paths='^.tox/.*' .

Pylint version

pylint 2.14.4
astroid 2.11.6
Python 3.10.5 (main, Jun 16 2022, 17:15:02) [GCC 12.1.1 20220518 (ALT Sisyphus 12.1.1-alt1)]

OS / Environment

ALTLinux

Additional dependencies

No response

@stanislavlevin stanislavlevin added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jun 30, 2022
@DanielNoord
Copy link
Collaborator

Closing as duplicate of #5398. We welcome any suggestions to allow both Windows as Unix paths as well as allowing \ to be used as escape character.

@DanielNoord DanielNoord closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2022
@DanielNoord DanielNoord added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants