How do I disable ruff for a specific line? #3442
-
I was wondering if there is a way to disable lint check/fix for one line of code. We have similar options in pylint. For example, I would like to do something like: # ruff: disable=F401
from abc.xyz import function_name Apologies if this has been answered previously; I couldn't find it in the Discussions. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
The most common would be to add a from abc.xyz import function_name # noqa: F401 If you want to ignore all errors on a line: from abc.xyz import function_name # noqa You can also disable all errors of a given kind across an entire file like so: # ruff: noqa: F401
from abc.xyz import function_name (More details in the docs.) |
Beta Was this translation helpful? Give feedback.
-
The difference between |
Beta Was this translation helpful? Give feedback.
-
Hi @charliermarsh, is there a way to disable ruff for a block of lines? |
Beta Was this translation helpful? Give feedback.
-
I only want to import
However, running this through python v3.11.4 |
Beta Was this translation helpful? Give feedback.
-
Here is a reduced script that triggers the ruff E402 error. Note the
comments "delete this". Delete those lines individually and adapt main to
circumvent syntax errors: Each deletion on its own weirdly make the E402
error disappear.
import sys # delete this and adapt main -> ruff error E402 disappears
"Delete this comment and the ruff error E402 disappears."
from pathlib import Path # delete this and adapt main -> ruff error E402
disappears
if __name__ == "__main__":
import os # noqa: E402
def main():
print(Path(sys.argv[0]))
print(os.name)
main()
…On Thu, Aug 3, 2023 at 10:11 PM Charlie Marsh ***@***.***> wrote:
Are you able to post a complete file for reproduction? (The error says
line 26.)
—
Reply to this email directly, view it on GitHub
<#3442 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADNESO2EGUHF3G3BSUYICTXTQAVTANCNFSM6AAAAAAVWSCZWY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
The most common would be to add a
noqa
inline, like so:If you want to ignore all errors on a line:
You can also disable all errors of a given kind across an entire file like so:
(More details in the docs.)