astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.14k stars 55 forks source link

Question: How to configure ruff source directory in vscode for sorting imports? #650

Open DanielBoxer opened 6 hours ago

DanielBoxer commented 6 hours ago

I'm working in a monorepo, so auto formatters aren't able to distinguish absolute path imports from external package imports, and they get grouped together.

With isort and black, I would set the source directory like this in .vscode/settings.json so it would group them separately:

{
    "isort.args": [
        "--src",
        "path/to/source/dir",
        "--profile",
        "black",
    ]
}

How can this be done with ruff?

dhruvmanila commented 4 hours ago

I think that should be done via the src setting in your Ruff configuration file. In an editor context, the server should pickup the settings. If you want to have a common settings for multiple projects, you could use the ruff.configuration option and specify that in your VS Code settings.