Closed a412h closed 5 months ago
You configure ruff-lsp like you configure ruff, see https://docs.astral.sh/ruff/configuration/
A concrete example would be greatly appreciated. What should I write, and where, to make ruff signal W291 ?
Ruff can be configured through a pyproject.toml, ruff.toml, or .ruff.toml file.
Contents for pyproject.toml
:
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "W"]
# -----add this-------------------^
In Ubuntu, where do I place such file so that Sublimetext uses it for ruff ?
The file must be in the project root, i.e. the folder you open with sublime text.
Isn't there a way to have one file for all projects, as a default configuration for ruff under sublimetext ?
This can be achieved with the lint.args
here Package Settings -> LSP -> Servers -> LSP-ruff, have a look in the documentation here https://github.com/astral-sh/ruff-lsp. This is only a bridge to ruff-lsp so all settings from there apply here.
The .toml file you provided works perfectly when placed at the root of a project. However, I don't know how to translate it into a json file; this has no effect (~/.config/sublime-text/Packages/User/LSP-ruff.sublime-settings):
{
"settings": {
"LSP": {
"LSP-ruff": {
"initializationOptions": {
"settings": {
"args": ["E", "F", "W"],
"preview": true
}
}
}
}
}
}
Description for lint.args
from here https://github.com/astral-sh/ruff-lsp
Additional command-line arguments to pass to ruff check, e.g., "args": ["--config=/path/to/pyproject.toml"]. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like --force-exclude and --verbose.
This means, you should use something like ["--config=/path/to/pyproject.toml"]
Could you please write the minimal working file under Package Settings -> LSP -> Servers -> LSP-ruff where I have to put the ["--config=/path/to/pyproject.toml"] (it is not clear from the documentation what fields the file must have) ?
A minimal working example of a file that allows a global configuration of Ruff: 1) Open Package Settings -> LSP -> Servers -> LSP-ruff 2) Save there the following lines:
{
"initializationOptions": {
"globalSettings": {
// Custom arguments passed to ruff.
// See ruff documentation at https://github.com/charliermarsh/ruff/blob/main/README.md#configuration
"lint.args": ["--config=/folder_of_your_toml_file/pyproject.toml"],
},
},
}
I have followed the installation procedure. Where do I configure Ruff for Sublimetext ? Should I configure the file accessible from: Package Settings -> LSP -> Servers -> LSP-ruff ? More precisely I need to lint following Flake8 and Pycodestyle, for example automatic detection of warnings, like W291. How and where do I do that ?