Skip to content

Commit

Permalink
Add example demonstrating that fmt: skip on expression level is not…
Browse files Browse the repository at this point in the history
… supported (#9973)
  • Loading branch information
MichaReiser authored Feb 13, 2024
1 parent 6f9c128 commit 46db3f9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions docs/formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ Instead, apply the `# fmt: off` comment to the entire statement:
# fmt: on
```

Like Black, Ruff will _also_ recognize [YAPF](https://github.com/google/yapf)'s `# yapf: disable` and `# yapf: enable` pragma
comments, which are treated equivalently to `# fmt: off` and `# fmt: on`, respectively.

`# fmt: skip` comments suppress formatting for a preceding statement, case header, decorator,
function definition, or class definition:

Expand All @@ -287,8 +290,30 @@ def test(a, b, c, d, e, f) -> int: # fmt: skip
pass
```

Like Black, Ruff will _also_ recognize [YAPF](https://github.com/google/yapf)'s `# yapf: disable` and `# yapf: enable` pragma
comments, which are treated equivalently to `# fmt: off` and `# fmt: on`, respectively.
As such, adding `# fmt: skip` comments at the end of an expressions will have no effect. In
the following example, the list entry `'1'` will be formatted, despite the `# fmt: skip`:

```python
a = call(
[
'1', # fmt: skip
'2',
],
b
)
```

Instead, apply the `# fmt: skip` comment to the entire statement:

```python
a = call(
[
'1',
'2',
],
b
) # fmt: skip
```

## Conflicting lint rules

Expand Down

0 comments on commit 46db3f9

Please sign in to comment.