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

"# noqa" is ignored when per-file-ignores is provided #3972

Closed
DmytroLitvinov opened this issue Apr 14, 2023 · 2 comments
Closed

"# noqa" is ignored when per-file-ignores is provided #3972

DmytroLitvinov opened this issue Apr 14, 2023 · 2 comments

Comments

@DmytroLitvinov
Copy link

Hi there.
I am trying to integrate ruff as a possible replacement of flake8 and I see that behavior of per-file-ignores option is not the same as in flake8.

  • flake8 settings
[flake8]
max-line-length = 120
per-file-ignores =
    __init__.py:F401,F403

flake8 respects noqa in that case, but not ruff. Not sure is it expected behavior for ruff or not?

  • Code snippet to reproduce the issue:
# __init__.py file
"""
See what is changed since then - https://github.com/ui/django-post_office/compare/3fead089a4e7e7fc2ae5ab56383f4ebf64c8777b...master  # noqa: E501
After you adapt it, then please change hash commit in url.
"""
  • Ruff settings:
# pyproject.toml
[tool.ruff]
line-length = 120
# Sync with flake8 configuration
[tool.ruff.per-file-ignores]
"__init__.py" = ["F401", "F403"]
  • Ruff version: 0.0.261
  • Ruff issue: __init__.py:2:121: E501 Line too long (144 > 120 characters)
@DmytroLitvinov
Copy link
Author

As far as I see right now also, it is not about per-file-ignores option, but because of docstrings.

"""
# docsting.py
https://github.com/robbitt07/django_boilerplate/blob/fcd03f03e9e9e54088cf69cd3c4bc83eabfd2666/utils/storage_backends.py#L8  # noqa: E501
"""

Issue: docstring.py:2:121: E501 Line too long (138 > 120 characters)

@charliermarsh
Copy link
Member

Yeah that's correct -- we don't support # noqa comments within multi-line strings. There's a note on it here. Instead, we respect # noqa comments at the end of docstrings, like:

"""
# docsting.py
https://github.com/robbitt07/django_boilerplate/blob/fcd03f03e9e9e54088cf69cd3c4bc83eabfd2666/utils/storage_backends.py#L8 
"""  # noqa: E501

Flake8 respects either variant, so changing this should retain Flake8 compatibility.

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

2 participants