danvk
danvk

Reputation: 16955

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:

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

Upvotes: 9

Views: 1344

Answers (1)

danvk
danvk

Reputation: 16955

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
    }
}

Upvotes: 5

Related Questions