Skip to content

Commit 015b459

Browse files
committed
Update README
1 parent 8a0270c commit 015b459

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

README.md

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,61 +28,43 @@ pip install "ruff<0.1.0" "python-lsp-ruff==1.5.3"
2828

2929
This plugin will disable `pycodestyle`, `pyflakes`, `mccabe` and `pyls_isort` by default, unless they are explicitly enabled in the client configuration.
3030
When enabled, all linting diagnostics will be provided by `ruff`.
31-
Sorting of the imports through `ruff` when formatting is enabled by default.
32-
The list of code fixes can be changed via the `pylsp.plugins.ruff.format` option.
3331

3432
Any codes given in the `format` option will only be marked as `fixable` for ruff during the formatting operation, the user has to make sure that these codes are also in the list of codes that ruff checks!
3533

36-
This example configuration for `neovim` shows how to always sort imports when running `textDocument/formatting`:
37-
38-
```lua
39-
lspconfig.pylsp.setup {
40-
settings = {
41-
pylsp = {
42-
plugins = {
43-
ruff = {
44-
enabled = true,
45-
extendSelect = { "I" },
46-
},
47-
}
48-
}
49-
}
50-
}
51-
```
52-
53-
## Code actions
54-
55-
`python-lsp-ruff` supports code actions as given by possible fixes by `ruff`. `python-lsp-ruff` also supports [unsafe fixes](https://docs.astral.sh/ruff/linter/#fix-safety).
56-
Fixes considered unsafe by `ruff` are marked `(unsafe)` in the code action.
57-
The `Fix all` code action *only* consideres safe fixes.
5834

5935
## Configuration
6036

6137
Configuration options can be passed to the python-language-server. If a `pyproject.toml`
62-
file is present in the project, `python-lsp-ruff` will use these configuration options.
63-
Note that any configuration options (except for `extendIgnore` and `extendSelect`, see
64-
[this issue](https://github.com/python-lsp/python-lsp-ruff/issues/19)) passed to ruff via
65-
`pylsp` are ignored if the project has a `pyproject.toml`.
66-
67-
The plugin follows [python-lsp-server's
68-
configuration](https://github.com/python-lsp/python-lsp-server/#configuration). These are
69-
the valid configuration keys:
70-
71-
- `pylsp.plugins.ruff.enabled`: Boolean to enable/disable the plugin. `true` by default.
72-
- `pylsp.plugins.ruff.config`: Path to optional `pyproject.toml` file.
73-
- `pylsp.plugins.ruff.exclude`: Exclude files from being checked by `ruff`.
74-
- `pylsp.plugins.ruff.executable`: Path to the `ruff` executable. Uses `os.executable -m "ruff"` by default.
75-
- `pylsp.plugins.ruff.ignore`: Error codes to ignore.
76-
- `pylsp.plugins.ruff.extendIgnore`: Same as ignore, but append to existing ignores.
77-
- `pylsp.plugins.ruff.lineLength`: Set the line-length for length checks.
78-
- `pylsp.plugins.ruff.perFileIgnores`: File-specific error codes to be ignored.
79-
- `pylsp.plugins.ruff.select`: List of error codes to enable.
80-
- `pylsp.plugins.ruff.extendSelect`: Same as select, but append to existing error codes.
81-
- `pylsp.plugins.ruff.format`: List of error codes to fix during formatting. Empty by default, use `["I"]` here to get import sorting as part of formatting.
82-
- `pylsp.plugins.ruff.unsafeFixes`: Boolean that enables/disables fixes that are marked "unsafe" by `ruff`. `false` by default.
83-
- `pylsp.plugins.ruff.preview`: Boolean that enables/disables rules & fixes that are marked "preview" by `ruff`. `false` by default.
84-
- `pylsp.plugins.ruff.severities`: Dictionary of custom severity levels for specific codes, see [below](#custom-severities).
85-
- `pylsp.plugins.ruff.targetVersion`: The minimum Python version to target.
38+
file is present in the project, `python-lsp-ruff` will ignore specific options (see below).
39+
40+
The plugin follows [python-lsp-server's configuration](https://github.com/python-lsp/python-lsp-server/#configuration).
41+
This example configuration using for `neovim` shows the possible optionsL
42+
43+
```lua
44+
pylsp = {
45+
plugins = {
46+
ruff = {
47+
enabled = true, -- Enable the plugin
48+
executable = "<path-to-ruff-bin>", -- Custom path to ruff
49+
path = "<path_to_custom_ruff_toml>", -- Custom config for ruff to use
50+
extendSelect = { "I" }, -- Rules that are additionally used by ruff
51+
extendIgnore = { "C90" }, -- Rules that are additionally ignored by ruff
52+
format = { "I" }, -- Rules that are marked as fixable by ruff that should be fixed when running textDocument/formatting
53+
severities = { ["D212"] = "I" }, -- Optional table of rules where a custom severity is desired
54+
unsafeFixes = false, -- Whether or not to offer unsafe fixes as code actions. Ignored with the "Fix All" action
55+
56+
-- Rules that are ignored when a pyproject.toml or ruff.toml is present:
57+
lineLength = 88, -- Line length to pass to ruff checking and formatting
58+
exclude = { "__about__.py" }, -- Files to be excluded by ruff checking
59+
select = { "F" }, -- Rules to be enabled by ruff
60+
ignore = { "D210" }, -- Rules to be ignored by ruff
61+
perFileIgnores = { ["__init__.py"] = "CPY001" }, -- Rules that should be ignored for specific files
62+
preview = false, -- Whether to enable the preview style linting and formatting.
63+
targetVersion = "py310", -- The minimum python version to target (applies for both linting and formatting).
64+
},
65+
}
66+
}
67+
```
8668

8769
For more information on the configuration visit [Ruff's homepage](https://beta.ruff.rs/docs/configuration/).
8870

@@ -96,3 +78,19 @@ For more information on the diagnostic severities please refer to
9678

9779
Note that `python-lsp-ruff` does *not* accept regex, and it will *not* check whether the error code exists. If the custom severity level is not displayed,
9880
please check first that the error code is correct and that the given value is one of the possible keys from above.
81+
82+
83+
## Code formatting
84+
85+
With `python-lsp-ruff>1.6.0` formatting is done using [ruffs own formatter](https://docs.astral.sh/ruff/formatter/).
86+
In addition, rules that should be fixed during the `textDocument/formatting` request can be added with the `format` option.
87+
88+
Coming from previous versions the only change is that `isort` rules are **not** applied by default.
89+
To enable sorting of imports using ruff's isort functionality, add `"I"` to the list of `format` rules.
90+
91+
92+
## Code actions
93+
94+
`python-lsp-ruff` supports code actions as given by possible fixes by `ruff`. `python-lsp-ruff` also supports [unsafe fixes](https://docs.astral.sh/ruff/linter/#fix-safety).
95+
Fixes considered unsafe by `ruff` are marked `(unsafe)` in the code action.
96+
The `Fix all` code action *only* consideres safe fixes.

0 commit comments

Comments
 (0)