From ff1d7b5fcee7643c211d31a0643b9ed35ed6f2ce Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Sat, 21 Oct 2023 11:50:25 +0200 Subject: [PATCH] [feat] Add setting for enabling/disabling Preview rules --- README.md | 5 +++-- pylsp_ruff/plugin.py | 3 +++ pylsp_ruff/settings.py | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71f02ea..926f556 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ The plugin follows [python-lsp-server's configuration](https://github.com/python-lsp/python-lsp-server/#configuration). These are the valid configuration keys: - - `pylsp.plugins.ruff.enabled`: boolean to enable/disable the plugin. `true` by default. + - `pylsp.plugins.ruff.enabled`: Boolean to enable/disable the plugin. `true` by default. - `pylsp.plugins.ruff.config`: Path to optional `pyproject.toml` file. - `pylsp.plugins.ruff.exclude`: Exclude files from being checked by `ruff`. - `pylsp.plugins.ruff.executable`: Path to the `ruff` executable. Uses `os.executable -m "ruff"` by default. @@ -73,7 +73,8 @@ the valid configuration keys: - `pylsp.plugins.ruff.select`: List of error codes to enable. - `pylsp.plugins.ruff.extendSelect`: Same as select, but append to existing error codes. - `pylsp.plugins.ruff.format`: List of error codes to fix during formatting. The default is `["I"]`, any additional codes are appended to this list. - - `pylsp.plugins.ruff.unsafeFixes`: boolean that enables/disables fixes that are marked "unsafe" by `ruff`. `false` by default. + - `pylsp.plugins.ruff.unsafeFixes`: Boolean that enables/disables fixes that are marked "unsafe" by `ruff`. `false` by default. + - `pylsp.plugins.ruff.preview`: Boolean that enables/disables rules & fixes that are marked "preview" by `ruff`. `false` by default. - `pylsp.plugins.ruff.severities`: Dictionary of custom severity levels for specific codes, see [below](#custom-severities). For more information on the configuration visit [Ruff's homepage](https://beta.ruff.rs/docs/configuration/). diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index a36babf..8b915e8 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -533,6 +533,9 @@ def build_arguments( if settings.line_length: args.append(f"--line-length={settings.line_length}") + if settings.preview: + args.append("--preview") + if settings.unsafe_fixes: args.append("--unsafe-fixes") diff --git a/pylsp_ruff/settings.py b/pylsp_ruff/settings.py index 0ccda7e..66e4c00 100644 --- a/pylsp_ruff/settings.py +++ b/pylsp_ruff/settings.py @@ -23,6 +23,7 @@ class PluginSettings: format: Optional[List[str]] = None + preview: bool = False unsafe_fixes: bool = False severities: Optional[Dict[str, str]] = None