From 5d7338d44ed8dc58bd0d72de664072f5495e433d Mon Sep 17 00:00:00 2001 From: Magnus Larsen Date: Sat, 25 Nov 2023 14:05:52 +0000 Subject: [PATCH] Add setting for enabling/disabling Preview rules (#54) --- 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 288bb40..5c2a5da 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,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. @@ -79,7 +79,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. Empty by default, use `["I"]` here to get import sorting as part of formatting. - - `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). - `pylsp.plugins.ruff.targetVersion`: The minimum Python version to target. diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 04782c5..6ef9cdf 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -571,6 +571,9 @@ def build_check_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 b5bc24d..2345ce1 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