ruff: per-file-ignores have inconsistent behavior in symlinked directories
I am trying to ignore the S101 rule in tests. I have a base ruff.toml which is used in pyproject.toml.
Adding this to ruff.toml doesn’t work:
[per-file-ignores]
"**/test/**" = ["S101"] # <- still warnings in tests
However, adding the same in pyproject.toml works:
[tool.ruff]
extend = "/path/to/ruff.toml"
[tool.ruff.per-file-ignores]
"**/test/**" = ["S101"] # <- this works as expected
I tried without wildcards as well and extend-per-file-ignores. Nothing added to ruff.toml is considered.
Ruff version: 0.0.284
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 18 (15 by maintainers)
Thank you for all those interesting insights. My actual setup is not using symlinks (I was just using tmp for the minimal example). Instead, ruff is running in a docker, with the ruff config located at
/presets/ruff.tomland the project mounted in/app.I couldn’t make it work with the
**/test/**regex, but it works if I use/app/**/test/**in theruff.toml. The problem is, a CI may mount the folders somewhere else in the docker container, so this is not good enough.I tried calling ruff with
ruff check /app, but still now luck.UPDATE: it seems adding a leading
/works ->/**/test/**.@derlin Thanks for the workaround! Adding a leading slash does work (
"/*/tests/*"seems to be sufficient)@charliermarsh With respect to ripgrep, I believe that code was originally written with
std::env::current_dir, which is a platform independent way of getting the CWD. And then an issue was filed pointing out cases where that fails, for example, when using ripgrep in a directory that had been removed. So in that context, querying forPWDis treated as a “fallback” to try and find the CWD even whencurrent_dirfails. Potentially flipping this to ask forPWDfirst and falling back tostd::env::current_dirmight indeed be the better path. I don’t think I considered symlinks in this context when writingcurrent_dir@qdegraaf added a minimal example of the problem: this has to do with the relative path taken from the
ruff.tomllocation instead of the root of the project.Sorry this wasn’t very clear. The problem actually seems to be when
ruff.tomlis not at the root of the python project that is linted. Find below a reproducible example.The structure is:
The content of
/tmp/ruff.toml:The content of
/tmp/ruff-example/pyproject.toml:Running from the root of
/tmpworks as expected:Running it from the root of the source directory
ruff-examplefails: