Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prioritize "Add import" over "Ruff: Disable" in Python / VS Code

I'm writing Python code in VS Code and have recently installed the Ruff linter and its associated VS Code extension. One thing I'm finding frustrating is that when I write a symbol name and want to use VS Code's "Quick Fix" to add an import for it, the first option that comes up is "Ruff: Disable" rather than "Add import".

Quick Fix showing "Ruff: Disable" first and Add import second

This isn't the end of the world, of course, I can press down arrow to select the action I want. But it does add an extra step and is an annoyance. Is there a way I can get these actions in the order I want?

A few versions if they're relevant:

  • Ruff extension, this happens with both v2023.16.0 and v2023.17.11351528
  • Pylance v2023.6.10
  • Python VS Code Extension v2023.8.0

VS Code version:

Version: 1.78.2 (Universal)
Commit: b3e4e68a0bc097f0ae7907b217c1119af9e03435
Date: 2023-05-10T14:44:45.204Z
Electron: 22.5.2
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Darwin arm64 22.5.0
Sandboxed: Yes
like image 734
danvk Avatar asked Mar 16 '26 15:03

danvk


1 Answers

There doesn't seem to be any way to adjust the order of these quick fixes. But it's possible to move "Add import" to the top of to the list by removing "Ruff: disable" quick fixes entirely.

Here's the setting for your .vscode/settings.json:

{
    "ruff.codeAction.disableRuleComment": {
        "enable": false
    }
}
like image 184
danvk Avatar answered Mar 19 '26 03:03

danvk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!