-
Notifications
You must be signed in to change notification settings - Fork 57
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
Support for disabling specific rules from auto-fixing on save #260
Comments
I totally agree. Especially once #247 is fixed the automatic fix of F401 and F841 might lead to confusion and annoyance. I guess we would need 2 configuration sets, one for creating the warnings/highlights and one for fixing. I would propose maybe something like this
|
I'm also interested as F401 drives me nut. I had to disable it altogether for now. |
This feature would be awesome, I have to keep re-typing imports whenever I comment out parts of the code while developing. |
Totally hear you. I should note that you can disable the fix for F401 entirely via: "ruff.args": [
"--unfixable=F401"
], This'll prevent Ruff from removing unused imports on save. But it'll also prevent Ruff from removing unused imports when you run "Fix all" and such, so it's not a perfect solution. |
Just discussed this with Charlie live at PyCon - we currently have
|
@aneeshusa Does #457 solve it? you can set new |
Note that in newer versions of ruff you need to set "ruff.lint.args": [
"--unfixable=F401"
], |
Hello, it does not work for me, unused imports are still deleted.
|
@amaurygelin The
|
Could we make it to accept json values? "ruff.nativeServer": true,
"ruff.configuration": {
"unfixable": ["F401", "F801"]
} we can either drop string value support for I believe this setting also helps to: |
We considered this for the configuration proposal but decided against it for now because:
There's an option to allow any value to pass through to Ruff, leaving validation to the executable. However, this might result in a less optimal user experience due to the lack of auto-completion and delayed feedback on settings correctness. |
I'm interested in supporting this and have created an issue with more details at astral-sh/ruff#12709. If anyone wants to work on this, feel free to ping me / comment on the Ruff issue. |
Does #702 solve this issue? |
Do you mean Ruff Extension can send lint diagnostics for
It needs investigation to check is there any other extensions that implemented auto-completion for settings.json. I think it makes sense at least provided a way from VSCode to let extension set auto-completion values dynamically during runtime instead of specifying statically in |
That's a good point. I think it can partially resolve it i.e., a user can configure Ruff in an editor context to mark certain rules as Consider this example config: {
"ruff.configuration": {
"lint": {
"unfixable": ["F541"]
}
}
} So, I think it's still useful to provide that feature so that the user still have the option to fix it if they want to.
No, I meant what we've implemented in astral-sh/ruff#16296 which is that
Yeah, I don't know if that's even possible because the extension would need to provide suggestion based on the selected |
Based on proposed solution above, We could have separate configuration for editor's CodeActions (e.g.
I prefer latter because I think we can also expand it for Format Document and I don't think it making sense for former one since document formatting isn't a CodeAction! "editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"ruff.onExecuteConfiguration.organizeImports": {
"extend-ignore": ["E203", "F841", "F401"]
} Note that Relevant issues: |
@T-256 Thank you for providing other options! I think any design discussions should be moved to astral-sh/ruff#12709 instead. |
When coding, it is annoying that our temporary imports and variables that we haven't yet used are removed every time we save the file.
We'd like the Ruff extension to auto-fix on save in general (and we have that activated using
editor.codeActionsOnSave
), but not F401 (unused imports) and F841 (unused variables).We do want the rule to autofix in other contexts (pre-commit hook, CI). Is there a way to do that?
The text was updated successfully, but these errors were encountered: