skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search