ruff
ruff copied to clipboard
[ENH] Let `fmt: skip` apply to compound statements, if they share a line.
if True: x = 0 # fmt: skip
def foo(self, lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, sed, do): ... # fmt: skip
Gets reformatted to
if True:
x = 0 # fmt: skip
def foo(
self, lorem, ipsum, dolor, sit, amet, consectetur, adipiscing, elit, sed, do
): ... # fmt: skip
Which is because fmt: skip only applies to the preceding statement. However, it would be useful to apply the fmt: skip to the whole compound statement in this context. For instance, when formatting @overload decorated functions.
Yeah that makes sense to me. I'm not entirely sure how to implement this yet. I see two approaches:
- Add special handling for
fmt: skipandfmt: off(and I thinkyapf:disable) comments inplacement.rsthat come at the end of a clause header. Instead of associating them with the preceding statement, associate them with the clause header (but only if both are on the same line). - Pass the comments of the first simple statement to
FormatClauseHeaderand make the decision there.
The good news, the unused formatter suppression comment lint rule seems to already accept this.
Hi @MichaReiser I did a first pass on this issue. Not sure if my approach is what we were looking for but I'd be happy to change direction. Let me know 👍 https://github.com/astral-sh/ruff/pull/13487