Shai Avr
Shai Avr

Reputation: 1350

How to ignore ruff errors in jupyter notebook in VSCode?

I am using ruff to lint and format my Python code in Visual Studio Code. I also work often with jupyter notebooks inside VSCode. When I do that I get some ruff linting errors that don't really make sense in a notebook such as Module level import not at top of cell:

In a Python file, this warning certainly makes sense, but not really in a notebook. I couldn't find how I could silence these warnings for notebooks specifically. There are no ruff settings related to notebooks and I couldn't find how to apply settings specifically to jupyter notebooks. Does somebody know how to silence these warnings inside a notebook in VSCode?

Upvotes: 1

Views: 2868

Answers (1)

Rejexx
Rejexx

Reputation: 79

Add this to your pyproject.toml:

[tool.ruff.lint.per-file-ignores]
"*.ipynb" = ["E402"]

This ignore the E402: module-import-not-at-top-of-file for all files ending in .ipynb. You can add more ignores specific to that notebooks type if needed like so: "*.ipynb" = ["E402", "E501"]

I'm pulling this from the ruff docs notebook documentation section, as Wayne mentioned in the OP comment.

Upvotes: 4

Related Questions