mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 15:17:59 +00:00
Fix PT006 autofix of parametrize name strings like ' first, , second '
(#1591)
This commit is contained in:
parent
b9e92affb1
commit
ebb31dc29b
5 changed files with 83 additions and 32 deletions
|
@ -11,6 +11,11 @@ def test_csv(param1, param2):
|
|||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(" param1, , param2 , ", [(1, 2), (3, 4)])
|
||||
def test_csv_with_whitespace(param1, param2):
|
||||
...
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
||||
def test_tuple(param1, param2):
|
||||
...
|
||||
|
|
|
@ -22,7 +22,19 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
|||
value: Constant::Str(string),
|
||||
..
|
||||
} => {
|
||||
let names = string.split(',').collect::<Vec<&str>>();
|
||||
// Match the following pytest code:
|
||||
// [x.strip() for x in argnames.split(",") if x.strip()]
|
||||
let names = string
|
||||
.split(',')
|
||||
.filter_map(|s| {
|
||||
let trimmed = s.trim();
|
||||
if trimmed.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(trimmed)
|
||||
}
|
||||
})
|
||||
.collect::<Vec<&str>>();
|
||||
|
||||
if names.len() > 1 {
|
||||
match names_type {
|
||||
|
|
|
@ -5,55 +5,55 @@ expression: checks
|
|||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 14
|
||||
row: 19
|
||||
column: 25
|
||||
end_location:
|
||||
row: 14
|
||||
row: 19
|
||||
column: 45
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 36
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 36
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 24
|
||||
row: 29
|
||||
column: 25
|
||||
end_location:
|
||||
row: 24
|
||||
row: 29
|
||||
column: 45
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
parent: ~
|
||||
|
||||
|
|
|
@ -20,47 +20,64 @@ expression: checks
|
|||
column: 40
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
ParametrizeNamesWrongType: tuple
|
||||
location:
|
||||
row: 19
|
||||
row: 14
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 14
|
||||
column: 56
|
||||
fix:
|
||||
content: "(\"param1\", \"param2\")"
|
||||
location:
|
||||
row: 14
|
||||
column: 25
|
||||
end_location:
|
||||
row: 14
|
||||
column: 56
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 24
|
||||
column: 36
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 36
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: tuple
|
||||
location:
|
||||
row: 24
|
||||
row: 29
|
||||
column: 25
|
||||
end_location:
|
||||
row: 24
|
||||
row: 29
|
||||
column: 45
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
parent: ~
|
||||
|
||||
|
|
|
@ -26,41 +26,58 @@ expression: checks
|
|||
column: 25
|
||||
end_location:
|
||||
row: 14
|
||||
column: 56
|
||||
fix:
|
||||
content: "[\"param1\", \"param2\"]"
|
||||
location:
|
||||
row: 14
|
||||
column: 25
|
||||
end_location:
|
||||
row: 14
|
||||
column: 56
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: list
|
||||
location:
|
||||
row: 19
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
column: 45
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 36
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 25
|
||||
end_location:
|
||||
row: 19
|
||||
row: 24
|
||||
column: 36
|
||||
parent: ~
|
||||
- kind:
|
||||
ParametrizeNamesWrongType: csv
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
fix:
|
||||
content: "\"param1\""
|
||||
location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 25
|
||||
end_location:
|
||||
row: 29
|
||||
row: 34
|
||||
column: 35
|
||||
parent: ~
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue