Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pylsp_ruff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def create_diagnostic(check: RuffCheck, settings: PluginSettings) -> Diagnostic:
# Ruff intends to implement severity codes in the future,
# see https://github.com/charliermarsh/ruff/issues/645.
severity = DiagnosticSeverity.Warning
if check.code == "None" or check.code == "E999" or check.code[0] == "F":
if check.code == "None" or check.code == "invalid-syntax" or check.code[0] == "F":
severity = DiagnosticSeverity.Error

# Check if check.code starts contained in given severities
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"
requires-python = ">=3.8"
license = {text = "MIT"}
dependencies = [
"ruff>=0.2.0",
"ruff>=0.8.0",
"python-lsp-server",
"cattrs!=23.2.1",
"lsprotocol>=2023.0.1",
Expand Down
24 changes: 23 additions & 1 deletion tests/test_ruff_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def using_const():
return t
"""

DOC_INVALID = r"""
a =
"""


@pytest.fixture()
def workspace(tmp_path):
Expand Down Expand Up @@ -74,6 +78,24 @@ def test_ruff_lint(workspace):
os.remove(name)


def test_ruff_invalid(workspace):
name, doc = temp_document(DOC_INVALID, workspace)
try:
diags = ruff_lint.pylsp_lint(workspace, doc)
assert len(diags) == 1
diag = diags[0]

assert diag["source"] == "ruff"
assert diag["code"] == "invalid-syntax"
assert diag["message"] == "Expected an expression"
assert diag["range"]["start"] == {"line": 1, "character": 4}
assert diag["range"]["end"] == {"line": 2, "character": 0}
assert diag["severity"] == lsp.DiagnosticSeverity.Error
assert diag["tags"] == []
finally:
os.remove(name)


def test_ruff_config_param(workspace):
with patch("pylsp_ruff.plugin.Popen") as popen_mock:
mock_instance = popen_mock.return_value
Expand Down Expand Up @@ -268,7 +290,7 @@ def f():

diags = ruff_lint.pylsp_lint(workspace, doc)
diag_codes = [diag["code"] for diag in diags]
assert "E999" not in diag_codes
assert "invalid-syntax" not in diag_codes
assert "E402" in diag_codes
assert "F401" in diag_codes
assert "F841" in diag_codes
Loading