mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
Allow # fmt: skip with interspersed same-line comments (#9395)
## Summary This is similar to https://github.com/astral-sh/ruff/pull/8876, but more limited in scope: 1. It only applies to `# fmt: skip` (like Black). Like `# isort: on`, `# fmt: on` needs to be on its own line (still). 2. It only delimits on `#`, so you can do `# fmt: skip # noqa`, but not `# fmt: skip - some other content` or `# fmt: skip; noqa`. If we want to support the `;`-delimited version, we should revisit later, since we don't support that in the linter (so `# fmt: skip; noqa` wouldn't register a `noqa`). Closes https://github.com/astral-sh/ruff/issues/8892.
This commit is contained in:
parent
4b8b3a1ced
commit
60ba7a7c0d
4 changed files with 66 additions and 13 deletions
|
|
@ -21,8 +21,7 @@ skip_will_not_work2 = "a" + "b" # some text; fmt:skip happens to be part of i
|
|||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,8 +1,8 @@
|
||||
-foo = 123 # fmt: skip # noqa: E501 # pylint
|
||||
+foo = 123 # fmt: skip # noqa: E501 # pylint
|
||||
foo = 123 # fmt: skip # noqa: E501 # pylint
|
||||
bar = (
|
||||
- 123 ,
|
||||
- ( 1 + 5 ) # pylint # fmt:skip
|
||||
|
|
@ -38,7 +37,7 @@ skip_will_not_work2 = "a" + "b" # some text; fmt:skip happens to be part of i
|
|||
## Ruff Output
|
||||
|
||||
```python
|
||||
foo = 123 # fmt: skip # noqa: E501 # pylint
|
||||
foo = 123 # fmt: skip # noqa: E501 # pylint
|
||||
bar = (
|
||||
123,
|
||||
(1 + 5), # pylint # fmt:skip
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/reason.py
|
||||
---
|
||||
## Input
|
||||
```python
|
||||
# Supported
|
||||
x = 1 # fmt: skip
|
||||
x = 1 # fmt: skip # reason
|
||||
x = 1 # reason # fmt: skip
|
||||
|
||||
# Unsupported
|
||||
x = 1 # fmt: skip reason
|
||||
x = 1 # fmt: skip - reason
|
||||
x = 1 # fmt: skip; noqa
|
||||
```
|
||||
|
||||
## Output
|
||||
```python
|
||||
# Supported
|
||||
x = 1 # fmt: skip
|
||||
x = 1 # fmt: skip # reason
|
||||
x = 1 # reason # fmt: skip
|
||||
|
||||
# Unsupported
|
||||
x = 1 # fmt: skip reason
|
||||
x = 1 # fmt: skip - reason
|
||||
x = 1 # fmt: skip; noqa
|
||||
```
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue