Skip to content

Stacking # noqa with other ignore comments causes an E501 (line too long) violation #18470

@user27182

Description

@user27182

Summary

The docs for E501 states that "a line will not be flagged as overlong if a pragma comment causes it to exceed the line length."

This works if the comment is # noqa, but seems to fail if there's any other preceding # (with some exceptions for # type: ignore, see below).

Reproducible with source:

def foo(arg=True):... ## noqa: FBT002

and settings:

{
  "line-length": 35,
  "lint": {
    "select": [
      "E501",
      "FBT"
    ]
  },
  "format": {}
}

The practical real-world use-case for this is when multiple linting tools and ignore comments are used, e.g. adding # noqa here where the line was previously not too long will cause a violation (but should not):

# numpydoc ignore=PR01  # noqa: FBT002

Interestingly, the # type: ignore case is handled properly, and does not cause a violation:

# type: ignore  # noqa: FBT002

Version

ruff v0.11.12 (using the ruff playground)

EDIT: For clarity:

This line is not too long:

def foo(arg=True):... #

But this line is:

def foo(arg=True):... ## noqa: FBT002

But, simply adding # noqa: FBT002 should not cause the line to be too long.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions