From cab0ad3461f5b4670984d65e0a6bfe36947b52c1 Mon Sep 17 00:00:00 2001 From: Kirk Strauser Date: Mon, 16 Oct 2023 17:18:46 -0700 Subject: [PATCH 1/3] Use --output-format instead of --output In https://github.com/astral-sh/ruff/pull/7984, ruff removed support for the "--output" command line option, and now requires "--output-format" instead. --- pylsp_ruff/plugin.py | 2 +- tests/test_ruff_lint.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index c9c62e1..9eae133 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -492,7 +492,7 @@ def build_arguments( # Suppress update announcements args.append("--quiet") # Use the json formatting for easier evaluation - args.append("--format=json") + args.append("--output-format=json") if fix: args.append("--fix") else: diff --git a/tests/test_ruff_lint.py b/tests/test_ruff_lint.py index 9f6bac0..abcbada 100644 --- a/tests/test_ruff_lint.py +++ b/tests/test_ruff_lint.py @@ -177,7 +177,7 @@ def f(): assert call_args == [ "ruff", "--quiet", - "--format=json", + "--output-format=json", "--no-fix", "--force-exclude", f"--stdin-filename={os.path.join(workspace.root_path, '__init__.py')}", From 44845b05bc13ecf31ba4501cdcd4ab24500303a5 Mon Sep 17 00:00:00 2001 From: Kirk Strauser Date: Mon, 16 Oct 2023 17:21:05 -0700 Subject: [PATCH 2/3] Again allow ruff to apply unsafe fixes Ruff 0.1.0 no longer applies unsafe fixes without explicit opt-in; see https://github.com/astral-sh/ruff/pull/7769 . This gives users a mechanism to enable them. --- pylsp_ruff/plugin.py | 4 ++++ pylsp_ruff/settings.py | 1 + tests/test_code_actions.py | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 9eae133..dd3c9bd 100644 --- a/pylsp_ruff/plugin.py +++ b/pylsp_ruff/plugin.py @@ -510,6 +510,9 @@ def build_arguments( if settings.line_length: args.append(f"--line-length={settings.line_length}") + if settings.unsafe_fixes: + args.append("--unsafe-fixes") + if settings.exclude: args.append(f"--exclude={','.join(settings.exclude)}") @@ -583,6 +586,7 @@ def load_settings(workspace: Workspace, document_path: str) -> PluginSettings: return PluginSettings( enabled=plugin_settings.enabled, executable=plugin_settings.executable, + unsafe_fixes=plugin_settings.unsafe_fixes, extend_ignore=plugin_settings.extend_ignore, extend_select=plugin_settings.extend_select, format=plugin_settings.format, diff --git a/pylsp_ruff/settings.py b/pylsp_ruff/settings.py index 7993183..5585e83 100644 --- a/pylsp_ruff/settings.py +++ b/pylsp_ruff/settings.py @@ -9,6 +9,7 @@ class PluginSettings: enabled: bool = True executable: str = "ruff" + unsafe_fixes: bool = False config: Optional[str] = None line_length: Optional[int] = None diff --git a/tests/test_code_actions.py b/tests/test_code_actions.py index 7e15de9..fa1bca2 100644 --- a/tests/test_code_actions.py +++ b/tests/test_code_actions.py @@ -115,6 +115,15 @@ def f(): pass """ ) + workspace._config.update( + { + "plugins": { + "ruff": { + "unsafeFixes": True, + } + } + } + ) _, doc = temp_document(codeaction_str, workspace) settings = ruff_lint.load_settings(workspace, doc.path) fixed_str = ruff_lint.run_ruff_fix(doc, settings) From fa42cfd1ccc16403c1f7d621e6ce80223e4d2935 Mon Sep 17 00:00:00 2001 From: Kirk Strauser Date: Mon, 16 Oct 2023 17:38:50 -0700 Subject: [PATCH 3/3] Only work with ruff 0.1.x as a dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bd52059..2922920 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ readme = "README.md" requires-python = ">=3.7" license = {text = "MIT"} dependencies = [ - "ruff>=0.0.267", + "ruff>=0.1.0, <0.2.0", "python-lsp-server", "lsprotocol>=2022.0.0a1", "tomli>=1.1.0; python_version < '3.11'",