Add example demonstrating that `fmt: skip` on expression level is not supported (#9973)

This commit is contained in:
Micha Reiser 2024-02-13 16:35:27 +01:00 committed by GitHub
parent 6f9c128d77
commit 46db3f96ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 2 deletions

View File

@ -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:
@ -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