astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.75k stars 1.07k forks source link

Feature request: include isort `line_length` option (to allow decouping of linting from formatting) #11290

Closed rwarren closed 5 months ago

rwarren commented 5 months ago

Ruff version: 0.4.3

Request in short:

It would be nice if Ruff's isort implementation supported isort's line_length setting independently from Ruff's global line-length setting.

The width threshold used for warning about line length issues should not exactly match the value used for automatic formatting (line wrapping). Warnings and auto-formatting are different things and it would be nice if Ruff didn't rigidly couple them.

This could be done here by just adding support for line_length in the lint.isort settings.

Rationale:

I use Ruff for linting, but do not use it for overall file formatting. I do use Ruff's embedded isort formatting extensively.

For linting the line length:

For automatic line length formatting:

In most cases long from ... import ... lines shouldn't happen in a code base, but (aside from this being a style choice) it is common in some libraries like PySide6, where lines like this are common:

from PySide6.QtWidgets import QGraphicsItem, QGraphicsLineItem, QGraphicsPixmapItem, QGraphicsScene, QGraphicsTextItem, QGraphicsView, QVBoxLayout

The isort implementation nicely generated that line... but it is too long because the linter line-length threshold is intentionally long, and Ruff is wrapping using it.

charliermarsh commented 5 months ago

Thanks, though I think this is a duplicate of #3206?

rwarren commented 5 months ago

... not sure how I missed #3206!! 🤦 It is a duplicate.

I think this is because I landed here after finding #4048 (about use_parentheses) and re-targeted the report while writing it.

Rationale here is basically in support of #3206. Shall I move the text over there?