Skip to content

Commit

Permalink
style: add None for empty return statements in server.py (#386)
Browse files Browse the repository at this point in the history
## Summary

Simply added `None` to empty return to maintain consistency with other
methods/functions that return None.
Example:

1.
https://github.com/astral-sh/ruff-lsp/blob/bae2b2488b09ae3dc1b411ce845db780738827ee/ruff_lsp/server.py#L622
2.
https://github.com/astral-sh/ruff-lsp/blob/bae2b2488b09ae3dc1b411ce845db780738827ee/ruff_lsp/server.py#L733
3. …

Also aligned with [PEP 8
recommendations](https://peps.python.org/pep-0008/#programming-recommendations)
"Be consistent in return statements …".

## Test Plan

N/A because both `return` and `return None` return None in the same way.
  • Loading branch information
mrKazzila committed Feb 17, 2024
1 parent bae2b24 commit 48c09d5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions ruff_lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ async def did_open(params: DidOpenTextDocumentParams) -> None:
)
settings = _get_settings_by_document(document.path)
if not lint_enable(settings):
return
return None

diagnostics = await _lint_document_impl(document, settings)
LSP_SERVER.publish_diagnostics(document.uri, diagnostics)
Expand All @@ -469,7 +469,7 @@ async def did_save(params: DidSaveTextDocumentParams) -> None:
text_document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
settings = _get_settings_by_document(text_document.path)
if not lint_enable(settings):
return
return None

if lint_run(settings) in (
Run.OnType,
Expand All @@ -486,7 +486,7 @@ async def did_change(params: DidChangeTextDocumentParams) -> None:
text_document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
settings = _get_settings_by_document(text_document.path)
if not lint_enable(settings):
return
return None

if lint_run(settings) == Run.OnType:
document = Document.from_text_document(text_document)
Expand All @@ -502,12 +502,12 @@ async def did_open_notebook(params: DidOpenNotebookDocumentParams) -> None:
)
if notebook_document is None:
log_warning(f"No notebook document found for {params.notebook_document.uri!r}")
return
return None

document = Document.from_notebook_document(notebook_document)
settings = _get_settings_by_document(document.path)
if not lint_enable(settings):
return
return None

diagnostics = await _lint_document_impl(document, settings)

Expand Down Expand Up @@ -571,12 +571,12 @@ async def _did_change_or_save_notebook(
)
if notebook_document is None:
log_warning(f"No notebook document found for {notebook_uri!r}")
return
return None

document = Document.from_notebook_document(notebook_document)
settings = _get_settings_by_document(document.path)
if not lint_enable(settings):
return
return None

if lint_run(settings) in run_types:
cell_diagnostics = _group_diagnostics_by_cell(
Expand Down Expand Up @@ -1173,11 +1173,11 @@ async def apply_autofix(arguments: tuple[TextDocument]):
document = Document.from_uri(uri)
settings = _get_settings_by_document(document.path)
if not lint_enable(settings):
return
return None

workspace_edit = await _fix_document_impl(document, settings)
if workspace_edit is None:
return
return None
LSP_SERVER.apply_edit(workspace_edit, "Ruff: Fix all auto-fixable problems")


Expand All @@ -1188,7 +1188,7 @@ async def apply_organize_imports(arguments: tuple[TextDocument]):
settings = _get_settings_by_document(document.path)
workspace_edit = await _fix_document_impl(document, settings, only=["I001", "I002"])
if workspace_edit is None:
return
return None
LSP_SERVER.apply_edit(workspace_edit, "Ruff: Format imports")


Expand Down Expand Up @@ -1660,7 +1660,7 @@ def _update_workspace_settings(settings: list[WorkspaceSettings]) -> None:
"workspacePath": workspace_path,
"workspace": uris.from_fs_path(workspace_path),
}
return
return None

for setting in settings:
if "workspace" in setting:
Expand Down

0 comments on commit 48c09d5

Please sign in to comment.