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
1 change: 1 addition & 0 deletions pylsp_ruff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def build_arguments(
args.append("--exit-zero")
# Use the json formatting for easier evaluation
args.append("--output-format=json")
args.append("--extension=ipynb:python")
if fix:
args.append("--fix")
else:
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.7"
license = {text = "MIT"}
dependencies = [
"ruff>=0.1.0, <0.2.0",
"ruff>=0.1.5, <0.2.0",
"python-lsp-server",
"lsprotocol>=2022.0.0a1",
"tomli>=1.1.0; python_version < '3.11'",
Expand Down
21 changes: 21 additions & 0 deletions tests/test_ruff_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def f():
"--quiet",
"--exit-zero",
"--output-format=json",
"--extension=ipynb:python",
"--no-fix",
"--force-exclude",
f"--stdin-filename={os.path.join(workspace.root_path, '__init__.py')}",
Expand Down Expand Up @@ -242,3 +243,23 @@ def f():
assert diag["code"] != "F401"

os.unlink(os.path.join(workspace.root_path, "pyproject.toml"))


def test_notebook_input(workspace):
doc_str = r"""
print('hi')
import os
def f():
a = 2
"""
# attribute the python code to a notebook file name per jupyterlab-lsp
doc_uri = uris.from_fs_path(os.path.join(workspace.root_path, "Untitled.ipynb"))
workspace.put_document(doc_uri, doc_str)
doc = workspace.get_document(doc_uri)

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