source.fixall formats but does not fix all issues
eugenenelou opened this issue · 10 comments
Hey, I have some rules with autofix available that are correctly fixed when running the command Ruff: Fix all auto-fixable problems
, but they are not fixed when saving, despite having the settings available to auto-fix on save.
On save formatting happens, but not autofixing.
here are my settings:
"[python]": {
"editor.formatOnSave": true,
"editor.formatOnPaste": false,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixall.ruff": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
},
Can you share a code example with the rules that you expect should be fixed when applying fix-all? I wonder if the fixes for those rules are marked as unsafe.
Currently it's the COM812
missing comma rule. the doc says Fix is always available.
(I tried setting "unsafe-fixes" to true, but maybe I did it wrong)
Thanks. Do you have a code example that you could share? Do you see any output in the Output: Ruff
tab indicating that there's an error?
I have nothing in the output apart from the initial setup that has no error.
example, the trailing comma should appear after []
:
for obj in list_with_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery_long_name(
[1]
):
print(obj)
The output is:
2024-08-17 16:42:50.489 [info] Name: Ruff
2024-08-17 16:42:50.489 [info] Module: ruff
2024-08-17 16:42:50.489 [info] Python extension loading
2024-08-17 16:42:50.489 [info] Waiting for interpreter from python extension.
2024-08-17 16:42:50.489 [info] Python extension loaded
2024-08-17 16:42:50.489 [info] Using interpreter: .../.venv/bin/python
2024-08-17 16:42:50.500 [info] Using the Ruff binary: .../.venv/bin/ruff
2024-08-17 16:42:50.509 [info] Resolved 'ruff.nativeServer: auto' to use the native server
2024-08-17 16:42:50.511 [info] Found Ruff 0.5.3 at .../.venv/bin/ruff
2024-08-17 16:42:50.511 [info] Server run command: .../.venv/bin/ruff server
2024-08-17 16:42:50.512 [info] Server: Start requested.
2024-08-17 16:42:50.547 [info] warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
I just tested your code example in VS code and it's working as expected. Could you share your ruff (pyproject.toml
/ruff.toml
) configuration with us?
Hey, sorry for the delay, here is my config:
[tool.ruff.lint]
select = ["ALL"]
# list of rules: https://docs.astral.sh/ruff/rules
ignore = [
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D106", # Missing docstring in public nested class
"TRY003", # Avoid specifying long messages outside the exception class
"ANN101", # Missing type annotation for {name} in method
"ANN001", # Missing type annotation for function argument {name}
"ANN002", # Missing type annotation for *{name}
"ANN003", # Missing type annotation for **{name}
"ANN201", # Missing return type annotation for public function {name}
"TD003", # add issue link in # TODO
"FIX002", # remove TODO comments
]
[tool.ruff]
line-length = 120
[tool.ruff.lint.per-file-ignores]
"**/tests/**/*.py" = ["S101", "ARG", "FBT", "D", "PLR2004"]
Thanks for providing the config. Running the "Ruff: Fix all auto-fixable problems" command does add the trailing comma after [1]
. I'm using Ruff 0.5.3, the same version as yours. Can you try it again and verify that the problem persists?
Yes it does, my problem is that the onSave
doesn't fix it.
Oh ok. I think I see the problem - in your VS Code settings, it should be "fixAll" and not "fixall" (uppercase "A").
Oh yes that works! thanks a lot.