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_nameApologies if this has been answered previously; I couldn't find it in the Discussions. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 18 replies
-
|
The most common would be to add a from abc.xyz import function_name # noqa: F401If you want to ignore all errors on a line: from abc.xyz import function_name # noqaYou 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.
-
|
Hi, sorry to dig it up, but is there any way to properly skip a single line for ANY syntax error ? my problem is that I use ruff for a cookiecutter template wich comes with a pytest case importing the package : import {{cookiecutter.project_slug}} as pkg # noqa ???this will trigger a invalid-syntax: Expected a statement
--> {{ cookiecutter.project_name }}\tests\test_package.py:1:38that I cannot remove ... exclude = ["** cookiecutter.project_name **/tests/test_package.py"] |
Beta Was this translation helpful? Give feedback.
The most common would be to add a
noqainline, 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.)