You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This plugin will disable `pycodestyle`, `pyflakes`, `mccabe` and `pyls_isort` by default, unless they are explicitly enabled in the client configuration.
30
30
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.
33
31
34
32
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!
35
33
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.
58
34
59
35
## Configuration
60
36
61
37
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
+
```
86
68
87
69
For more information on the configuration visit [Ruff's homepage](https://beta.ruff.rs/docs/configuration/).
88
70
@@ -95,3 +77,19 @@ For more information on the diagnostic severities please refer to
95
77
[the official LSP reference](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticSeverity).
96
78
97
79
With `v2.0.0` it is also possible to use patterns to match codes. Rules match if the error code starts with the given pattern. If multiple patterns match the error code, `python-lsp-ruff` chooses the one with the most amount of matching characters.
80
+
81
+
82
+
## Code formatting
83
+
84
+
With `python-lsp-ruff>1.6.0` formatting is done using [ruffs own formatter](https://docs.astral.sh/ruff/formatter/).
85
+
In addition, rules that should be fixed during the `textDocument/formatting` request can be added with the `format` option.
86
+
87
+
Coming from previous versions the only change is that `isort` rules are **not** applied by default.
88
+
To enable sorting of imports using ruff's isort functionality, add `"I"` to the list of `format` rules.
89
+
90
+
91
+
## Code actions
92
+
93
+
`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).
94
+
Fixes considered unsafe by `ruff` are marked `(unsafe)` in the code action.
95
+
The `Fix all` code action *only* consideres safe fixes.
0 commit comments