mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 22:10:48 -05:00
Add autofix for W605 [InvalidEscapeSequence] (#1361)
This commit is contained in:
@@ -188,6 +188,7 @@ pub fn invalid_escape_sequence(
|
||||
locator: &SourceCodeLocator,
|
||||
start: Location,
|
||||
end: Location,
|
||||
autofix: bool,
|
||||
) -> Vec<Check> {
|
||||
let mut checks = vec![];
|
||||
|
||||
@@ -235,13 +236,17 @@ pub fn invalid_escape_sequence(
|
||||
};
|
||||
let location = Location::new(start.row() + row_offset, col);
|
||||
let end_location = Location::new(location.row(), location.column() + 2);
|
||||
checks.push(Check::new(
|
||||
let mut check = Check::new(
|
||||
CheckKind::InvalidEscapeSequence(next_char),
|
||||
Range {
|
||||
location,
|
||||
end_location,
|
||||
},
|
||||
));
|
||||
);
|
||||
if autofix {
|
||||
check.amend(Fix::insertion(r"\".to_string(), location));
|
||||
}
|
||||
checks.push(check);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 2
|
||||
column: 11
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 2
|
||||
column: 9
|
||||
end_location:
|
||||
row: 2
|
||||
column: 9
|
||||
- kind:
|
||||
InvalidEscapeSequence: "."
|
||||
location:
|
||||
@@ -19,7 +26,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 6
|
||||
column: 2
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 0
|
||||
- kind:
|
||||
InvalidEscapeSequence: _
|
||||
location:
|
||||
@@ -28,7 +42,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 11
|
||||
column: 7
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 11
|
||||
column: 5
|
||||
end_location:
|
||||
row: 11
|
||||
column: 5
|
||||
- kind:
|
||||
InvalidEscapeSequence: _
|
||||
location:
|
||||
@@ -37,5 +58,12 @@ expression: checks
|
||||
end_location:
|
||||
row: 18
|
||||
column: 7
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 18
|
||||
column: 5
|
||||
end_location:
|
||||
row: 18
|
||||
column: 5
|
||||
|
||||
|
||||
@@ -10,7 +10,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 2
|
||||
column: 11
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 2
|
||||
column: 9
|
||||
end_location:
|
||||
row: 2
|
||||
column: 9
|
||||
- kind:
|
||||
InvalidEscapeSequence: "."
|
||||
location:
|
||||
@@ -19,7 +26,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 6
|
||||
column: 2
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 6
|
||||
column: 0
|
||||
end_location:
|
||||
row: 6
|
||||
column: 0
|
||||
- kind:
|
||||
InvalidEscapeSequence: _
|
||||
location:
|
||||
@@ -28,7 +42,14 @@ expression: checks
|
||||
end_location:
|
||||
row: 11
|
||||
column: 7
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 11
|
||||
column: 5
|
||||
end_location:
|
||||
row: 11
|
||||
column: 5
|
||||
- kind:
|
||||
InvalidEscapeSequence: _
|
||||
location:
|
||||
@@ -37,5 +58,12 @@ expression: checks
|
||||
end_location:
|
||||
row: 18
|
||||
column: 7
|
||||
fix: ~
|
||||
fix:
|
||||
content: "\\"
|
||||
location:
|
||||
row: 18
|
||||
column: 5
|
||||
end_location:
|
||||
row: 18
|
||||
column: 5
|
||||
|
||||
|
||||
Reference in New Issue
Block a user