mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:37 +00:00
Add newline if B006 fix is at end-of-file (#7090)
This commit is contained in:
parent
dbb34804a4
commit
37d244d178
3 changed files with 31 additions and 1 deletions
|
@ -308,3 +308,7 @@ def single_line_func_wrong(value: dict[str, str] = {
|
|||
def single_line_func_wrong(value: dict[str, str] = {}) \
|
||||
: \
|
||||
"""Docstring"""
|
||||
|
||||
|
||||
def single_line_func_wrong(value: dict[str, str] = {}):
|
||||
"""Docstring without newline"""
|
|
@ -175,8 +175,15 @@ fn move_initialization(
|
|||
return None;
|
||||
}
|
||||
Edit::insertion(content, locator.line_start(statement.start()))
|
||||
} else if statement.end() == locator.text_len() {
|
||||
// If the statement is at the end of the file, without a trailing newline, insert
|
||||
// _after_ it with an extra newline.
|
||||
Edit::insertion(
|
||||
format!("{}{}", stylist.line_ending().as_str(), content),
|
||||
locator.full_line_end(statement.end()),
|
||||
)
|
||||
} else {
|
||||
// If the docstring is the only statement, insert _before_ it.
|
||||
// If the docstring is the only statement, insert _after_ it.
|
||||
Edit::insertion(content, locator.full_line_end(statement.end()))
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -476,4 +476,23 @@ B006_B008.py:308:52: B006 Do not use mutable data structures for argument defaul
|
|||
|
|
||||
= help: Replace with `None`; initialize within function
|
||||
|
||||
B006_B008.py:313:52: B006 [*] Do not use mutable data structures for argument defaults
|
||||
|
|
||||
313 | def single_line_func_wrong(value: dict[str, str] = {}):
|
||||
| ^^ B006
|
||||
314 | """Docstring without newline"""
|
||||
|
|
||||
= help: Replace with `None`; initialize within function
|
||||
|
||||
ℹ Possible fix
|
||||
310 310 | """Docstring"""
|
||||
311 311 |
|
||||
312 312 |
|
||||
313 |-def single_line_func_wrong(value: dict[str, str] = {}):
|
||||
314 |- """Docstring without newline"""
|
||||
313 |+def single_line_func_wrong(value: dict[str, str] = None):
|
||||
314 |+ """Docstring without newline"""
|
||||
315 |+ if value is None:
|
||||
316 |+ value = {}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue