Skip to content

Keep # noqa comments when forcing single-line imports #3418

@stinodego

Description

@stinodego

Consider the following file repro.py:

from datetime import date, time  # noqa: F401

And let's say my ruff config has isort lints, with force-single-line option:

[tool.ruff]
fix = true
select = ["F", "I"]

[tool.ruff.isort]
force-single-line = true

Running ruff repro.py results in the time import being deleted:

from datetime import date  # noqa: F401

Running ruff repro.py --unfixable=F401 results in:

from datetime import date  # noqa: F401
from datetime import time

So the problem here is that the # noqa comment is not reproduced on the extra lines. Desired outcome would be:

from datetime import date  # noqa: F401
from datetime import time  # noqa: F401

This is on the latest version of ruff (0.0.254).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingisortRelated to import sorting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions