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

pyproject.toml fix-only=True cannot be toggled per directory by using multiple pyproject.toml files and the extend setting. #15801

Open
jogo-openai opened this issue Jan 29, 2025 · 1 comment
Labels
configuration Related to settings and configuration needs-decision Awaiting a decision from a maintainer

Comments

@jogo-openai
Copy link

Description

I am trying to enable fix-only for some directories and not for others, while running ruff check . in the repo root directory.

Ruff fix-only config option doesn't seem to use the 'closest' config file for each individual file.

https://docs.astral.sh/ruff/configuration/#config-file-discovery

$ ruff --version
ruff 0.9.3
├── foo
│   ├── bar.py
│   └── pyproject.toml
└── pyproject.toml

pyproject.toml:

[tool.ruff]
lint.select = ["F"]

foo/pyproject.toml:

[tool.ruff]
extend = "../pyproject.toml"
fix-only = true

foo/bar.py:

import os

from __future__ import annotations

When running ruff check from the root directory here, I expect it to use fix-onlyfromfoo/pyproject.tomlsince it's the closest config file tofoo/bar.py` but it doesn't.

$ ruff check .
foo/bar.py:1:8: F401 [*] `os` imported but unused
  |
1 | import os
  |        ^^ F401
2 |
3 | from __future__ import annotations
  |
  = help: Remove unused import: `os`

foo/bar.py:3:1: F404 `from __future__` imports must occur at the beginning of the file
  |
1 | import os
2 |
3 | from __future__ import annotations
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F404
  |

Found 2 errors.
[*] 1 fixable with the `--fix` option.

When running from the directory foo, the same command respects fix-only from foo/pyproject.toml.

$ ruff check .
Fixed 1 error.
@dylwil3 dylwil3 added bug Something isn't working configuration Related to settings and configuration and removed bug Something isn't working labels Jan 29, 2025
@dylwil3
Copy link
Collaborator

dylwil3 commented Jan 29, 2025

Thank you! I'm able to reproduce this behavior.

Trying to decide if this should be a bug, feature request, or expected behavior that is not documented. For comparison, the same sort of thing happens if you have conflicting settings for output-format or show-fixes, etc. It feels like it should be expected behavior for "display" settings but a bug/feature request for settings like fix and fix-only. But this probably needs some input from others.

@dylwil3 dylwil3 added the needs-decision Awaiting a decision from a maintainer label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Related to settings and configuration needs-decision Awaiting a decision from a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants