Skip to content
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

Respect per-file-ignore directory globs for files passed via stdin #1840

Closed
john-kurkowski opened this issue Jan 13, 2023 · 2 comments · Fixed by #1843
Closed

Respect per-file-ignore directory globs for files passed via stdin #1840

john-kurkowski opened this issue Jan 13, 2023 · 2 comments · Fixed by #1843

Comments

@john-kurkowski
Copy link

john-kurkowski commented Jan 13, 2023

per-file-ignore filename globs are respected when running Ruff against . and stdin. However, directory globs are not respected when running Ruff against stdin.

❯ ruff --version
ruff 0.0.220

❯ mkdir ruff-example
❯ cd ruff-example
❯ mkdir tests
❯ echo 'import os' > tests/foo.py

❯ ruff --isolated .
tests/foo.py:1:8: F401 `os` imported but unused
Found 1 error(s).
1 potentially fixable with the --fix option.

# so far so good

❌1 ❮ ruff --isolated --per-file-ignores='foo*:F401' .

# filename glob match OK!

❯ ruff --isolated --per-file-ignores='tests/*:F401' .

# directory glob match OK!

❯ ruff --isolated --per-file-ignores='foo*:F401' --stdin-filename 'tests/foo.py' - < tests/foo.py

# filename glob match OK!

❯ ruff --isolated --per-file-ignores='tests/*:F401' --stdin-filename 'tests/foo.py' - < tests/foo.py
tests/foo.py:1:8: F401 `os` imported but unused
Found 1 error(s).
1 potentially fixable with the --fix option.

# directory glob match not ok

❌1 ❮

Related to #1342?

@charliermarsh
Copy link
Member

Thanks, I'll look into this!

charliermarsh added a commit that referenced this issue Jan 13, 2023
Non-basename glob matches (e.g., for `--per-file-ignores`) assume that
the path has been converted to an absolute path. (We do this for
filenames as part of the directory traversal.) For filenames passed via
stdin, though, we're missing this conversion. So `--per-file-ignores`
that rely on the _basename_ worked as expected, but directory paths did
not.

Closes #1840.
@john-kurkowski
Copy link
Author

❤️ Thanks for Ruff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants