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.
2
Answers
In line with wath @InSync says, I found this solution:
Change this line
to:
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.
ruff.format.args
is the command line arguments that will be passed toruff
the executable. That is, the extension is running this command: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.