mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +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)])
|
@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)])
|
||||||
def test_tuple(param1, param2):
|
def test_tuple(param1, param2):
|
||||||
...
|
...
|
||||||
|
|
|
@ -22,7 +22,19 @@ fn check_names(checker: &mut Checker, expr: &Expr) {
|
||||||
value: Constant::Str(string),
|
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 {
|
if names.len() > 1 {
|
||||||
match names_type {
|
match names_type {
|
||||||
|
|
|
@ -5,55 +5,55 @@ expression: checks
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 14
|
row: 19
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 14
|
row: 19
|
||||||
column: 45
|
column: 45
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 36
|
column: 36
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 36
|
column: 36
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 24
|
row: 29
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 24
|
row: 29
|
||||||
column: 45
|
column: 45
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
parent: ~
|
parent: ~
|
||||||
|
|
||||||
|
|
|
@ -20,47 +20,64 @@ expression: checks
|
||||||
column: 40
|
column: 40
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: tuple
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 14
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
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
|
column: 36
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 36
|
column: 36
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: tuple
|
ParametrizeNamesWrongType: tuple
|
||||||
location:
|
location:
|
||||||
row: 24
|
row: 29
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 24
|
row: 29
|
||||||
column: 45
|
column: 45
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
parent: ~
|
parent: ~
|
||||||
|
|
||||||
|
|
|
@ -26,41 +26,58 @@ expression: checks
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 14
|
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
|
column: 45
|
||||||
fix: ~
|
fix: ~
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 36
|
column: 36
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 19
|
row: 24
|
||||||
column: 36
|
column: 36
|
||||||
parent: ~
|
parent: ~
|
||||||
- kind:
|
- kind:
|
||||||
ParametrizeNamesWrongType: csv
|
ParametrizeNamesWrongType: csv
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
fix:
|
fix:
|
||||||
content: "\"param1\""
|
content: "\"param1\""
|
||||||
location:
|
location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 25
|
column: 25
|
||||||
end_location:
|
end_location:
|
||||||
row: 29
|
row: 34
|
||||||
column: 35
|
column: 35
|
||||||
parent: ~
|
parent: ~
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue