mirror of https://github.com/astral-sh/ruff
Fix B006 when function docstring is followed by whitespace but no newline (#7160)
This commit is contained in:
parent
b60b37e866
commit
d68041ba24
|
|
@ -0,0 +1,5 @@
|
|||
# Docstring followed by a newline
|
||||
|
||||
def foobar(foor, bar={}):
|
||||
"""
|
||||
"""
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Docstring followed by whitespace with no newline
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/7155
|
||||
|
||||
def foobar(foor, bar={}):
|
||||
"""
|
||||
"""
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Docstring with no newline
|
||||
|
||||
|
||||
def foobar(foor, bar={}):
|
||||
"""
|
||||
"""
|
||||
|
|
@ -33,6 +33,9 @@ mod tests {
|
|||
#[test_case(Rule::JumpStatementInFinally, Path::new("B012.py"))]
|
||||
#[test_case(Rule::LoopVariableOverridesIterator, Path::new("B020.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_B008.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_1.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_2.py"))]
|
||||
#[test_case(Rule::MutableArgumentDefault, Path::new("B006_3.py"))]
|
||||
#[test_case(Rule::NoExplicitStacklevel, Path::new("B028.py"))]
|
||||
#[test_case(Rule::RaiseLiteral, Path::new("B016.py"))]
|
||||
#[test_case(Rule::RaiseWithoutFromInsideExcept, Path::new("B904.py"))]
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ fn move_initialization(
|
|||
return None;
|
||||
}
|
||||
Edit::insertion(content, locator.line_start(statement.start()))
|
||||
} else if statement.end() == locator.text_len() {
|
||||
} else if locator.full_line_end(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(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
B006_1.py:3:22: B006 [*] Do not use mutable data structures for argument defaults
|
||||
|
|
||||
1 | # Docstring followed by a newline
|
||||
2 |
|
||||
3 | def foobar(foor, bar={}):
|
||||
| ^^ B006
|
||||
4 | """
|
||||
5 | """
|
||||
|
|
||||
= help: Replace with `None`; initialize within function
|
||||
|
||||
ℹ Possible fix
|
||||
1 1 | # Docstring followed by a newline
|
||||
2 2 |
|
||||
3 |-def foobar(foor, bar={}):
|
||||
3 |+def foobar(foor, bar=None):
|
||||
4 4 | """
|
||||
5 5 | """
|
||||
6 |+
|
||||
7 |+ if bar is None:
|
||||
8 |+ bar = {}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
B006_2.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
||||
|
|
||||
2 | # Regression test for https://github.com/astral-sh/ruff/issues/7155
|
||||
3 |
|
||||
4 | def foobar(foor, bar={}):
|
||||
| ^^ B006
|
||||
5 | """
|
||||
6 | """
|
||||
|
|
||||
= help: Replace with `None`; initialize within function
|
||||
|
||||
ℹ Possible fix
|
||||
1 1 | # Docstring followed by whitespace with no newline
|
||||
2 2 | # Regression test for https://github.com/astral-sh/ruff/issues/7155
|
||||
3 3 |
|
||||
4 |-def foobar(foor, bar={}):
|
||||
4 |+def foobar(foor, bar=None):
|
||||
5 5 | """
|
||||
6 |- """
|
||||
6 |+ """
|
||||
7 |+ if bar is None:
|
||||
8 |+ bar = {}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/flake8_bugbear/mod.rs
|
||||
---
|
||||
B006_3.py:4:22: B006 [*] Do not use mutable data structures for argument defaults
|
||||
|
|
||||
4 | def foobar(foor, bar={}):
|
||||
| ^^ B006
|
||||
5 | """
|
||||
6 | """
|
||||
|
|
||||
= help: Replace with `None`; initialize within function
|
||||
|
||||
ℹ Possible fix
|
||||
1 1 | # Docstring with no newline
|
||||
2 2 |
|
||||
3 3 |
|
||||
4 |-def foobar(foor, bar={}):
|
||||
4 |+def foobar(foor, bar=None):
|
||||
5 |+ """
|
||||
5 6 | """
|
||||
6 |- """
|
||||
7 |+ if bar is None:
|
||||
8 |+ bar = {}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue