Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress ruff linting on a block of code

Tags:

python

lint

ruff

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?

like image 731
db_ Avatar asked Dec 02 '25 03:12

db_


2 Answers

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

like image 60
db_ Avatar answered Dec 04 '25 17:12

db_


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

like image 32
Boketto Avatar answered Dec 04 '25 16:12

Boketto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!