Skip to content

Commit 217a7fe

Browse files
betaboonjhossbach
authored andcommitted
feat: support import-sorting during formatting
1 parent 8b85881 commit 217a7fe

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ There also exists an [AUR package](https://aur.archlinux.org/packages/python-lsp
2222
This plugin will disable `flake8`, `pycodestyle`, `pyflakes` and `mccabe` by default.
2323
When enabled, all linting diagnostics will be provided by `ruff`.
2424

25+
This plugin will disable `pyls_isort` by default.
26+
When enabled, sorting of imports when formatting will be provided by `ruff`.
27+
2528
# Configuration
2629

2730
Configuration options can be passed to the python-language-server. If a `pyproject.toml`

pylsp_ruff/plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def pylsp_settings():
5959
"flake8": {"enabled": False},
6060
"mccabe": {"enabled": False},
6161
"pycodestyle": {"enabled": False},
62+
"pyls_isort": {"enabled": False},
6263
}
6364
}
6465
return converter.unstructure(settings)
@@ -345,11 +346,10 @@ def run_ruff_fix(workspace: Workspace, document: Document) -> str:
345346

346347
def run_ruff_format(workspace: Workspace, document: Document) -> str:
347348
settings = load_settings(workspace, document)
348-
extra_arguments = []
349+
fixable_codes = ["I"]
349350
if settings.format:
350-
extra_arguments.append(f"--fixable={','.join(settings.format)}")
351-
else:
352-
extra_arguments.append("--unfixable=ALL")
351+
fixable_codes.extend(settings.format)
352+
extra_arguments = [f"--fixable={','.join(fixable_codes)}"]
353353
result = run_ruff(workspace, document, fix=True, extra_arguments=extra_arguments)
354354
return result
355355

0 commit comments

Comments
 (0)