Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
def test():
# fmt: off
a_very_small_indent
(
not_fixed
)

if True:
pass
more
# fmt: on

formatted

def test():
a_small_indent
# fmt: off
# fix under-indented comments
(or_the_inner_expression +
expressions
)

if True:
pass
# fmt: on


# fmt: off
def test():
pass

# It is necessary to indent comments because the following fmt: on comment because it otherwise becomes a trailing comment
# of the `test` function if the "proper" indentation is larger than 2 spaces.
# fmt: on

disabled + formatting;

# fmt: on

formatted;

def test():
pass
# fmt: off
"""A multiline strings
that should not get formatted"""

"A single quoted multiline \
string"

disabled + formatting;

# fmt: on

formatted;
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,61 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off
---
## Input
```python
def test():
# fmt: off
a_very_small_indent
(
not_fixed
)

if True:
pass
more
# fmt: on

formatted

def test():
a_small_indent
# fmt: off
# fix under-indented comments
(or_the_inner_expression +
expressions
)

if True:
pass
# fmt: on


# fmt: off
def test():
pass

# It is necessary to indent comments because the following fmt: on comment because it otherwise becomes a trailing comment
# of the `test` function if the "proper" indentation is larger than 2 spaces.
# fmt: on

disabled + formatting;

# fmt: on

formatted;

def test():
pass
# fmt: off
"""A multiline strings
that should not get formatted"""

"A single quoted multiline \
string"

disabled + formatting;

# fmt: on

formatted;
```

## Outputs
Expand All @@ -23,6 +78,63 @@ source_type = Python
```

```python
def test():
# fmt: off
a_very_small_indent
(
not_fixed
)

if True:
pass
more
# fmt: on

formatted

def test():
a_small_indent
# fmt: off
# fix under-indented comments
(or_the_inner_expression +
expressions
)

if True:
pass
# fmt: on


# fmt: off
def test():
pass

# It is necessary to indent comments because the following fmt: on comment because it otherwise becomes a trailing comment
# of the `test` function if the "proper" indentation is larger than 2 spaces.
# fmt: on

disabled + formatting;

# fmt: on

formatted


def test():
pass
# fmt: off
"""A multiline strings
that should not get formatted"""

"A single quoted multiline \
string"

disabled + formatting;


# fmt: on

formatted
```


Expand All @@ -42,6 +154,63 @@ source_type = Python
```

```python
def test():
# fmt: off
a_very_small_indent
(
not_fixed
)

if True:
pass
more
# fmt: on

formatted

def test():
a_small_indent
# fmt: off
# fix under-indented comments
(or_the_inner_expression +
expressions
)

if True:
pass
# fmt: on


# fmt: off
def test():
pass

# It is necessary to indent comments because the following fmt: on comment because it otherwise becomes a trailing comment
# of the `test` function if the "proper" indentation is larger than 2 spaces.
# fmt: on

disabled + formatting;

# fmt: on

formatted


def test():
pass
# fmt: off
"""A multiline strings
that should not get formatted"""

"A single quoted multiline \
string"

disabled + formatting;


# fmt: on

formatted
```


Expand All @@ -61,4 +230,61 @@ source_type = Python
```

```python
def test():
# fmt: off
a_very_small_indent
(
not_fixed
)

if True:
pass
more
# fmt: on

formatted

def test():
a_small_indent
# fmt: off
# fix under-indented comments
(or_the_inner_expression +
expressions
)

if True:
pass
# fmt: on


# fmt: off
def test():
pass

# It is necessary to indent comments because the following fmt: on comment because it otherwise becomes a trailing comment
# of the `test` function if the "proper" indentation is larger than 2 spaces.
# fmt: on

disabled + formatting;

# fmt: on

formatted


def test():
pass
# fmt: off
"""A multiline strings
that should not get formatted"""

"A single quoted multiline \
string"

disabled + formatting;


# fmt: on

formatted
```