Skip to content

Commit

Permalink
Again allow ruff to apply unsafe fixes
Browse files Browse the repository at this point in the history
Ruff 0.1.0 no longer applies unsafe fixes without explicit opt-in; see
astral-sh/ruff#7769 . This gives users a
mechanism to enable them.
  • Loading branch information
kstrauser authored and jhossbach committed Oct 18, 2023
1 parent b26fa3b commit eafbe5b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pylsp_ruff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")

Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pylsp_ruff/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_code_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eafbe5b

Please sign in to comment.