From ff6ddda5662b9529493251ad61647c37dc56a9b2 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 6 Feb 2025 11:24:27 -0500 Subject: [PATCH 1/2] CI: Pin Ruff to a specific version for code format checks That prevents constantly reformatting code to fit the changes introduced by new Ruff versions. --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 3bba01c8..6ec4345d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -39,7 +39,7 @@ jobs: # This error cannot be resolved by adding a pylint: disable=unused-argument comment ... - run: | pip install -e .[pylint,pycodestyle] - pip install ruff + pip install ruff==0.9.4 - name: ruff linter and code style checks run: ruff check pylsp test - name: ruff code formatter check From 8aa264dc30f9ca58f0917b898feac401053c9156 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Thu, 6 Feb 2025 11:29:57 -0500 Subject: [PATCH 2/2] Fix formatting issues reported by the latest Ruff version --- pylsp/_utils.py | 2 +- test/plugins/test_completion.py | 2 ++ test/test_utils.py | 4 ++-- test/test_workspace.py | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pylsp/_utils.py b/pylsp/_utils.py index 1be7e263..b96df5a9 100644 --- a/pylsp/_utils.py +++ b/pylsp/_utils.py @@ -19,7 +19,7 @@ # Eol chars accepted by the LSP protocol # the ordering affects performance EOL_CHARS = ["\r\n", "\r", "\n"] -EOL_REGEX = re.compile(f'({"|".join(EOL_CHARS)})') +EOL_REGEX = re.compile(f"({'|'.join(EOL_CHARS)})") log = logging.getLogger(__name__) diff --git a/test/plugins/test_completion.py b/test/plugins/test_completion.py index 3e768f06..b8de8912 100644 --- a/test/plugins/test_completion.py +++ b/test/plugins/test_completion.py @@ -65,6 +65,7 @@ class TypeCase(NamedTuple): expected: lsp.CompletionItemKind +# fmt: off TYPE_CASES: Dict[str, TypeCase] = { "variable": TypeCase( document="test = 1\ntes", @@ -115,6 +116,7 @@ class TypeCase(NamedTuple): expected=lsp.CompletionItemKind.Property, ), } +# fmt: on @pytest.mark.parametrize("case", list(TYPE_CASES.values()), ids=list(TYPE_CASES.keys())) diff --git a/test/test_utils.py b/test/test_utils.py index 07d04e34..966c469e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -45,14 +45,14 @@ def notebook_with_python_cells(cells: List[str]): "cells": [ { "kind": NotebookCellKind.Code, - "document": f"cell_{i+1}_uri", + "document": f"cell_{i + 1}_uri", } for i in range(len(cells)) ], }, "cellTextDocuments": [ { - "uri": f"cell_{i+1}_uri", + "uri": f"cell_{i + 1}_uri", "languageId": "python", "text": cell, } diff --git a/test/test_workspace.py b/test/test_workspace.py index dabbdf86..41bac398 100644 --- a/test/test_workspace.py +++ b/test/test_workspace.py @@ -238,7 +238,7 @@ def test_workspace_loads_pycodestyle_config(pylsp, tmpdir) -> None: # Test that project settings are loaded workspace2_dir = tmpdir.mkdir("NewTest456") cfg = workspace2_dir.join("pycodestyle.cfg") - cfg.write("[pycodestyle]\n" "max-line-length = 1000") + cfg.write("[pycodestyle]\nmax-line-length = 1000") workspace1 = {"uri": str(workspace1_dir)} workspace2 = {"uri": str(workspace2_dir)} @@ -257,7 +257,7 @@ def test_workspace_loads_pycodestyle_config(pylsp, tmpdir) -> None: # Test switching to another workspace with different settings workspace3_dir = tmpdir.mkdir("NewTest789") cfg1 = workspace3_dir.join("pycodestyle.cfg") - cfg1.write("[pycodestyle]\n" "max-line-length = 20") + cfg1.write("[pycodestyle]\nmax-line-length = 20") workspace3 = {"uri": str(workspace3_dir)} @@ -310,9 +310,9 @@ def test_progress_simple(workspace, consumer) -> None: assert init_call[0][0]["method"] == "window/workDoneProgress/create" # same method for all calls - assert all( - call[0][0]["method"] == "$/progress" for call in progress_calls - ), consumer.call_args_list + assert all(call[0][0]["method"] == "$/progress" for call in progress_calls), ( + consumer.call_args_list + ) # same token used in all calls assert (