Skip to content

Commit

Permalink
feat: support import-sorting during formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
betaboon committed Apr 9, 2023
1 parent fcf5979 commit bdd50df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ There also exists an [AUR package](https://aur.archlinux.org/packages/python-lsp
This plugin will disable `flake8`, `pycodestyle`, `pyflakes` and `mccabe` by default.
When enabled, all linting diagnostics will be provided by `ruff`.

This plugin will disable `pyls_isort` by default.
When enabled, sorting of imports when formatting will be provided by `ruff`.

# Configuration

Configuration options can be passed to the python-language-server. If a `pyproject.toml`
Expand Down
8 changes: 4 additions & 4 deletions pylsp_ruff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def pylsp_settings():
"flake8": {"enabled": False},
"mccabe": {"enabled": False},
"pycodestyle": {"enabled": False},
"pyls_isort": {"enabled": False},
}
}
return converter.unstructure(settings)
Expand Down Expand Up @@ -345,11 +346,10 @@ def run_ruff_fix(workspace: Workspace, document: Document) -> str:

def run_ruff_format(workspace: Workspace, document: Document) -> str:
settings = load_settings(workspace, document)
extra_arguments = []
fixable_codes = ["I"]
if settings.format:
extra_arguments.append(f"--fixable={','.join(settings.format)}")
else:
extra_arguments.append("--unfixable=ALL")
fixable_codes.extend(settings.format)
extra_arguments = [f"--fixable={','.join(fixable_codes)}"]
result = run_ruff(workspace, document, fix=True, extra_arguments=extra_arguments)
return result

Expand Down

0 comments on commit bdd50df

Please sign in to comment.