Skip to content

Commit 76ec182

Browse files
committed
feat: Add unfixable config option
1 parent ed4ae39 commit 76ec182

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pylsp = {
9191
"D212": "I"
9292
},
9393
"unsafeFixes": false,
94+
"unfixable": [ "F401" ],
9495
"lineLength": 88,
9596
"exclude": ["__about__.py"],
9697
"select": ["F"],

pylsp_ruff/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ def load_settings(workspace: Workspace, document_path: str) -> PluginSettings:
760760
extend_select=plugin_settings.extend_select,
761761
format=plugin_settings.format,
762762
severities=plugin_settings.severities,
763+
unfixable=plugin_settings.unfixable,
763764
)
764765

765766
return plugin_settings

tests/test_code_actions.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def f():
5050
"Ruff: Fix All (safe fixes)",
5151
]
5252

53+
codeactions_unfixable = [
54+
"Ruff (F401): Remove unused import: `os`",
55+
"Ruff (F401): Disable for this line",
56+
# "Ruff (F841): Remove assignment to unused variable `a` (unsafe)",
57+
"Ruff (F841): Disable for this line",
58+
"Ruff: Fix All (safe fixes)",
59+
]
60+
5361
codeactions_import = [
5462
"Ruff: Organize imports",
5563
"Ruff: Fix All (safe fixes)",
@@ -85,6 +93,24 @@ def test_ruff_code_actions(workspace):
8593
assert sorted(codeactions) == sorted(action_titles)
8694

8795

96+
def test_ruff_code_actions_unfixable(workspace):
97+
_, doc = temp_document(codeaction_str, workspace)
98+
99+
workspace._config.update(
100+
{"plugins": {"ruff": {"select": ["F"], "unfixable": ["F841"]}}}
101+
)
102+
diags = ruff_lint.pylsp_lint(workspace, doc)
103+
range_ = cattrs.unstructure(
104+
Range(start=Position(line=0, character=0), end=Position(line=0, character=0))
105+
)
106+
actions = ruff_lint.pylsp_code_actions(
107+
workspace._config, workspace, doc, range=range_, context={"diagnostics": diags}
108+
)
109+
actions = converter.structure(actions, List[CodeAction])
110+
action_titles = list(map(lambda action: action.title, actions))
111+
assert sorted(codeactions_unfixable) == sorted(action_titles)
112+
113+
88114
def test_import_action(workspace):
89115
workspace._config.update(
90116
{

0 commit comments

Comments
 (0)