mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
Indent statements in suppressed ranges (#6507)
This commit is contained in:
parent
e1e213decf
commit
232b44a8ca
18 changed files with 852 additions and 59 deletions
3
crates/ruff_python_formatter/resources/test/fixtures/ruff/.editorconfig
vendored
Normal file
3
crates/ruff_python_formatter/resources/test/fixtures/ruff/.editorconfig
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[mixed_space_and_tab.py]
|
||||
generated_code = true
|
||||
ij_formatter_enabled = false
|
|
@ -10,8 +10,13 @@ a + b # a trailing comment
|
|||
def test():
|
||||
pass
|
||||
|
||||
# trailing comment that falls into the verbatim range
|
||||
# under indent
|
||||
|
||||
def nested():
|
||||
...
|
||||
|
||||
# trailing comment that falls into the verbatim range
|
||||
# trailing outer comment
|
||||
# fmt: on
|
||||
|
||||
a + b
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[
|
||||
{
|
||||
"indent_style": { "Space": 4 }
|
||||
},
|
||||
{
|
||||
"indent_style": { "Space": 2 }
|
||||
}
|
||||
]
|
11
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/indent.options.json
vendored
Normal file
11
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/indent.options.json
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
[
|
||||
{
|
||||
"indent_style": { "Space": 4 }
|
||||
},
|
||||
{
|
||||
"indent_style": { "Space": 1 }
|
||||
},
|
||||
{
|
||||
"indent_style": "Tab"
|
||||
}
|
||||
]
|
55
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/indent.py
vendored
Normal file
55
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/indent.py
vendored
Normal file
|
@ -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;
|
|
@ -0,0 +1,11 @@
|
|||
[
|
||||
{
|
||||
"indent_style": { "Space": 4 }
|
||||
},
|
||||
{
|
||||
"indent_style": { "Space": 2 }
|
||||
},
|
||||
{
|
||||
"indent_style": "Tab"
|
||||
}
|
||||
]
|
15
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/mixed_space_and_tab.py
vendored
Normal file
15
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/mixed_space_and_tab.py
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
def test():
|
||||
# fmt: off
|
||||
a_very_small_indent
|
||||
(
|
||||
not_fixed
|
||||
)
|
||||
|
||||
if True:
|
||||
# Fun tab, space, tab, space. Followed by space, tab, tab, space
|
||||
pass
|
||||
more
|
||||
else:
|
||||
other
|
||||
# fmt: on
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue