diff --git a/pylsp_ruff/plugin.py b/pylsp_ruff/plugin.py index 2342b99..e69ea3c 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: @@ -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/pyproject.toml b/pyproject.toml index f96f12e..1d374e3 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,<0.1.0", + "ruff>=0.1.0, <0.2.0", "python-lsp-server", "lsprotocol>=2022.0.0a1", "tomli>=1.1.0; python_version < '3.11'", 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) 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')}",