3dSpatialUser
3dSpatialUser

Reputation: 2406

VSCode ruff ignores ruff.toml

For a project I have created a ruff.toml file. In this file is among other things a different line-length defined. When ruff is used from the cli ruff format it works as expected. But when I use Ruff: format document from the extension it goes back to the line length defined in my VSCode settings.

This a part of all my settings, but these are all settings containing ruff:

{
    "ruff.format.args": [
        "--line-length=79"
    ],
    "ruff.configurationPreference": "filesystemFirst",
    "editor.defaultFormatter": "charliermarsh.ruff",
    "notebook.defaultFormatter": "charliermarsh.ruff",
}

I expect that this line: "ruff.configurationPreference": "filesystemFirst", defines to first look a t the file system, if no .toml file is found, then it should use the default settings.

Upvotes: 1

Views: 504

Answers (2)

3dSpatialUser
3dSpatialUser

Reputation: 2406

In line with wath @InSync says, I found this solution:

Change this line

    "ruff.format.args": [
        "--line-length=79"
    ],

to:

    "ruff.lineLength": 79,

Now ruff formats files (or folders) without a .toml file using the default settings (like this line length). If there is a .toml file ruff uses those settings.

Upvotes: 0

InSync
InSync

Reputation: 10683

ruff.format.args is the command line arguments that will be passed to ruff the executable. That is, the extension is running this command:

$ ruff format --line-length=79

It is this argument that is overriding your configuration file.

To avoid this, either unset the workspace or user-level ruff.format.args, or set it to ["--config=/path/to/ruff.toml"]. Alternatively, set "ruff.nativeServer": "on" to use the Rust-based server, which has formatting capabilities.

Upvotes: 0

Related Questions