mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[pylint
] Supress PLE2510
/2512
/2513
/2514
/2515
autofix if the text contains an odd number of backslashes (#18856)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
96660d93ca
commit
659ecba477
8 changed files with 13 additions and 8 deletions
Binary file not shown.
|
@ -193,6 +193,15 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo
|
|||
let location = token.start() + TextSize::try_from(column).unwrap();
|
||||
let c = match_.chars().next().unwrap();
|
||||
let range = TextRange::at(location, c.text_len());
|
||||
|
||||
let is_escaped = &text[..column]
|
||||
.chars()
|
||||
.rev()
|
||||
.take_while(|c| *c == '\\')
|
||||
.count()
|
||||
% 2
|
||||
== 1;
|
||||
|
||||
let (replacement, diagnostic) = match c {
|
||||
'\x08' => (
|
||||
"\\b",
|
||||
|
@ -223,7 +232,7 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo
|
|||
continue;
|
||||
};
|
||||
|
||||
if !token.unwrap_string_flags().is_raw_string() {
|
||||
if !token.unwrap_string_flags().is_raw_string() && !is_escaped {
|
||||
let edit = Edit::range_replacement(replacement.to_string(), range);
|
||||
diagnostic.set_fix(Fix::safe_edit(edit));
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -232,14 +232,10 @@ if True:
|
|||
#[test]
|
||||
fn quick_test() {
|
||||
let source = r#"
|
||||
def main() -> None:
|
||||
if True:
|
||||
some_very_long_variable_name_abcdefghijk = Foo()
|
||||
some_very_long_variable_name_abcdefghijk = some_very_long_variable_name_abcdefghijk[
|
||||
some_very_long_variable_name_abcdefghijk.some_very_long_attribute_name
|
||||
== "This is a very long string abcdefghijk"
|
||||
]
|
||||
def hello(): ...
|
||||
|
||||
@lambda _, /: _
|
||||
class A: ...
|
||||
"#;
|
||||
let source_type = PySourceType::Python;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue