Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to tell ruff to ignore comments? #5899

Closed
xeon826 opened this issue Jul 19, 2023 · 10 comments
Closed

Is there a way to tell ruff to ignore comments? #5899

xeon826 opened this issue Jul 19, 2023 · 10 comments

Comments

@xeon826
Copy link

xeon826 commented Jul 19, 2023

Since Ruff is made to work in unison with Black, and Black doesn't reformat comments that exceed the line length, is there a way to tell Ruff to ignore these?

@zanieb
Copy link
Member

zanieb commented Jul 19, 2023

@xeon826 if you're using Black to enforce your line length I'd just recommend disabling E501 e.g. https://github.com/PrefectHQ/prefect/blob/a3a2f84ba17b8a4469f29fc2a2bfc6dbffd40ed0/.ruff.toml#L1-L2

@xeon826
Copy link
Author

xeon826 commented Jul 19, 2023

I'm using ruff-pre-commit and I added that to its ignore as a workaround but I'm also using ruff as a linting tool and it gives me the diagnostic if comments exceed the line length, I feel like --ignore-comments would be a useful feature.

@zanieb
Copy link
Member

zanieb commented Jul 19, 2023

Why don't you put it in your Ruff configuration so it is always applied?

Note this is also a duplicate of #4429 and #4595

We cover this in the FAQ too.

@xeon826
Copy link
Author

xeon826 commented Jul 19, 2023

I use it to check for line length as a linting tool in my environment, if I ignored E501 all together, I wouldn't get that behavior.
image

pyproject.toml

[tool.autoflake]
remove-all-unused-imports = true
in-place = true
expand-star-imports = true
remove-unused-variables = true

[tool.black]
line-length = 88
skip-string-normalization = true
skip-magic-trailing-comma = true
preview = true
target-version = ['py39']

[tool.isort]
profile = 'black'

[tool.ruff]
line-length = 88
target-version = 'py39'
fix = true

[tool.flake8]
max-line-length = 88

[tool.vulture]
exclude = ['venv', 'pod_v3', 'frontend-ops', 'labelbox', 'compute_v2']
paths = ['webapp']
min_confidence = 60
ignore_names = ["visit_*", "do_*"]
sort_by_size = true

@tylerlaprade
Copy link
Contributor

Black doesn't reformat comments that exceed the line length

@xeon826, are you referring to lines containing only a comment? Black has often rearranged my # type: ignore and # noqa comments, much to my chagrin, especially because I always include descriptive messages about why I'm ignoring something on that line.

@tylerlaprade
Copy link
Contributor

As an aside, @xeon826, you can 100% replace the functionality of autoflake and isort with ruff, including all the customization in your pyproject.toml. This is 99% likely to be true of flake8 as well, unless you are enabling some esoteric extension rules outside of your pyproject.toml

@xeon826
Copy link
Author

xeon826 commented Jul 24, 2023

@tylerlaprade Lines that are only a comment, yes. I'd remove autoflake but ruff doesn't include the expand-star-imports feature

@zanieb
Copy link
Member

zanieb commented Aug 15, 2023

Since this is a duplicate and there's a workaround I'm going to close this for bookkeeping purposes. Thanks for raising!

@zanieb zanieb closed this as completed Aug 15, 2023
@Qinhaifu
Copy link

Qinhaifu commented Nov 17, 2023

I'm using ruff-pre-commit and I added that to its ignore as a workaround but I'm also using ruff as a linting tool and it gives me the diagnostic if comments exceed the line length, I feel like --ignore-comments would be a useful feature.

i think so too. --ignore-comments would be a useful feature, sometimes we want to write code like this.

demo_code = generate_anything()  # some comments and this line length exceed 79 that i config.

@tapyu
Copy link

tapyu commented Sep 24, 2024

--line-length <LINE_LENGTH> Set the line-length

Don't we have a solution for this yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants