Skip to content

Commit fb54915

Browse files
committed
Add a test case to test_ruff_format.py
Update existing test text to be compatible with the case that a format is run with `format` set to `["ALL"]`.
1 parent 55a170c commit fb54915

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

tests/test_ruff_format.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"""
2020
).strip()
2121

22+
_UNUSED_IMPORTS = tw.dedent(
23+
"""
24+
import unused_import
25+
"""
26+
).strip()
27+
2228
_SORTED_IMPORTS = tw.dedent(
2329
"""
2430
import asyncio
@@ -30,19 +36,19 @@
3036

3137
_UNFORMATTED_CODE = tw.dedent(
3238
"""
33-
def foo(): pass
34-
def bar(): pass
39+
def foo(): return asyncio.subprocess.DEVNULL
40+
def bar(): return x(io.DEFAULT_BUFFER_SIZE)
3541
"""
3642
).strip()
3743

3844
_FORMATTED_CODE = tw.dedent(
3945
"""
4046
def foo():
41-
pass
47+
return asyncio.subprocess.DEVNULL
4248
4349
4450
def bar():
45-
pass
51+
return x(io.DEFAULT_BUFFER_SIZE)
4652
"""
4753
).strip()
4854

@@ -121,3 +127,22 @@ def test_ruff_format_and_sort_imports(workspace):
121127
)
122128
got = run_plugin_format(workspace, doc)
123129
assert want == got
130+
131+
132+
def test_ruff_format_via_all(workspace):
133+
# If `pylsp.plugins.ruff.format` contains "ALL", formatting should apply
134+
# the automatic fixes for unsorted-imports (I001) and unused-import (F401)
135+
txt = f"{_UNUSED_IMPORTS}\n{_UNSORTED_IMPORTS}\n{_UNFORMATTED_CODE}"
136+
want = f"{_SORTED_IMPORTS}\n\n\n{_FORMATTED_CODE}\n"
137+
_, doc = temp_document(txt, workspace)
138+
workspace._config.update(
139+
{
140+
"plugins": {
141+
"ruff": {
142+
"format": ["ALL"],
143+
}
144+
}
145+
}
146+
)
147+
got = run_plugin_format(workspace, doc)
148+
assert want == got

0 commit comments

Comments
 (0)