How can I suppress ruff linting on a block of code

644 Views Asked by At

I would like to disable/suppress the ruff linter (or certain linting rules) on a block of code. I know that I can do this for single lines (by using # noqa: <rule_code> at the end of the line) or for entire files/folder (#ruff: noqa <rule_code> at the top of the file).

However, I would like to disable the linter ruff on one function or on a multi-line block of code, but not an entire file. Is there a way to do this, without adding noqa to the end of each line?

2

There are 2 best solutions below

0
On

Not currently possible (as of 29 Jan 2024). See here for updates on the issue

1
On

You did not specify this in your question, but if this is about ruff format, and you want to generally disable it for a block of code, you can actually do this using the fmt comment:

# fmt: off

def my_unformatted_function():
   do_something()

# fmt: on