- Notifications
You must be signed in to change notification settings - Fork25
Linter plugin for pylsp based on ruff.
License
python-lsp/python-lsp-ruff
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
python-lsp-ruff
is a plugin forpython-lsp-server
that adds linting, code action and formatting capabilities that are provided byruff,an extremely fast Python linter and formatter written in Rust.
In the samevirtualenv
aspython-lsp-server
:
pip install python-lsp-ruff
There also exists anAUR package.
Ruff version0.1.0
introduced API changes that are fixed in Python LSP Ruffv1.6.0
. To continue withruff<0.1.0
please usev1.5.3
, e.g. usingpip
:
pip install"ruff<0.1.0""python-lsp-ruff==1.5.3"
This plugin will disablepycodestyle
,pyflakes
,mccabe
,autopep8
, andyapf
by default, unless they are explicitly enabled in the client configuration.Whenpython-lsp-ruff
is enabled, all linting diagnostics and formatting capabilities will be provided byruff
.
Any codes given in theformat
option will only be marked asfixable
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!
Configuration options can be passed to the python-language-server. If apyproject.toml
file is present in the project,python-lsp-ruff
will ignore specific options (see below).
The plugin followspython-lsp-server's configuration.This example configuration using forneovim
shows the possible options:
Lua
pylsp= {plugins= {ruff= {enabled=true,-- Enable the pluginformatEnabled=true,-- Enable formatting using ruffs formatterexecutable="<path-to-ruff-bin>",-- Custom path to ruffconfig="<path_to_custom_ruff_toml>",-- Custom config for ruff to useextendSelect= {"I"},-- Rules that are additionally used by ruffextendIgnore= {"C90"},-- Rules that are additionally ignored by ruffformat= {"I"},-- Rules that are marked as fixable by ruff that should be fixed when running textDocument/formattingseverities= { ["D212"]="I"},-- Optional table of rules where a custom severity is desiredunsafeFixes=false,-- Whether or not to offer unsafe fixes as code actions. Ignored with the "Fix All" action-- Rules that are ignored when a pyproject.toml or ruff.toml is present:lineLength=88,-- Line length to pass to ruff checking and formattingexclude= {"__about__.py"},-- Files to be excluded by ruff checkingselect= {"F"},-- Rules to be enabled by ruffignore= {"D210"},-- Rules to be ignored by ruffperFileIgnores= { ["__init__.py"]="CPY001"},-- Rules that should be ignored for specific filespreview=false,-- Whether to enable the preview style linting and formatting.targetVersion="py310",-- The minimum python version to target (applies for both linting and formatting). }, }}
JSON
{ "pylsp": { "plugins": { "ruff": { "enabled": true, "formatEnabled": true, "executable": "<path-to-ruff-bin>", "config": "<path_to_custom_ruff_toml>", "extendSelect": [ "I" ], "extendIgnore": [ "C90"], "format": [ "I" ], "severities": { "D212": "I" }, "unsafeFixes": false, "lineLength": 88, "exclude": ["__about__.py"], "select": ["F"], "ignore": ["D210"], "perFileIgnores": { "__init__.py": "CPY001" }, "preview": false, "targetVersion": "py310" } } }}
For more information on the configuration visitRuff's homepage.
By default, all diagnostics are marked as warning, except for"E999"
and all error codes starting with"F"
, which are displayed as errors.This default can be changed through thepylsp.plugins.ruff.severities
option, which takes the error code as a key and any of"E"
,"W"
,"I"
and"H"
to be displayed as errors, warnings, information and hints, respectively.For more information on the diagnostic severities please refer tothe official LSP reference.
Withv2.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.
Withpython-lsp-ruff>1.6.0
formatting is done usingruffs own formatter by default.Formatting using ruff can be explicitly disabled by settingformatEnabled = false
in the LSP settings.Additional rules that should be fixed during thetextDocument/formatting
request can be added with theformat
option.
Coming from previous versions the only change is thatisort
rules arenot applied by default.To enable sorting of imports using ruff's isort functionality, add"I"
to the list offormat
rules.
python-lsp-ruff
supports code actions as given by possible fixes byruff
.python-lsp-ruff
also supportsunsafe fixes.Fixes considered unsafe byruff
are marked(unsafe)
in the code action.TheFix all
code actiononly consideres safe fixes.
The log level can be set via thecmd
option ofpylsp
:
lspconfig.pylsp.setup {cmd= {"pylsp","-vvv","--log-file","/tmp/lsp.log"},settings= {pylsp= {plugins= {ruff= {enabled=true, }, } } }}
About
Linter plugin for pylsp based on ruff.
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.