From 50e1ecc086d8aee95af3348379217e31c8bef162 Mon Sep 17 00:00:00 2001 From: ember91 <31469580+ember91@users.noreply.github.com> Date: Fri, 8 Aug 2025 14:25:11 +0200 Subject: [PATCH] [`pylint`] Use lowercase hex characters to match the formatter (`PLE2513`) (#19808) PLE2513 --fix changes ESC and SUB to uppercase hexadecimal values such as \x1B while the formatter changes them to lowercase \x1b ## Summary ## Test Plan --------- Co-authored-by: Brent Westbrook --- crates/ruff_db/src/diagnostic/render/full.rs | 10 +++++----- .../pylint/rules/invalid_string_characters.rs | 18 +++++++++--------- ..._tests__PLE2512_invalid_characters.py.snap | Bin 4544 -> 4544 bytes ..._tests__PLE2513_invalid_characters.py.snap | Bin 5044 -> 5044 bytes 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/ruff_db/src/diagnostic/render/full.rs b/crates/ruff_db/src/diagnostic/render/full.rs index b42f4043f0..9cd15ce6bd 100644 --- a/crates/ruff_db/src/diagnostic/render/full.rs +++ b/crates/ruff_db/src/diagnostic/render/full.rs @@ -186,7 +186,7 @@ print() /// For example, without the fix, we get diagnostics like this: /// /// ``` - /// error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1A" instead + /// error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1a" instead /// --> example.py:1:25 /// | /// 1 | nested_fstrings = f'␈{f'{f'␛'}'}' @@ -206,13 +206,13 @@ print() .builder( "invalid-character-sub", Severity::Error, - r#"Invalid unescaped character SUB, use "\x1A" instead"#, + r#"Invalid unescaped character SUB, use "\x1a" instead"#, ) .primary("example.py", "1:24", "1:24", "") .build(); insta::assert_snapshot!(env.render(&diagnostic), @r#" - error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1A" instead + error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1a" instead --> example.py:1:25 | 1 | nested_fstrings = f'␈{f'{f'␛'}'}' @@ -231,13 +231,13 @@ print() .builder( "invalid-character-sub", Severity::Error, - r#"Invalid unescaped character SUB, use "\x1A" instead"#, + r#"Invalid unescaped character SUB, use "\x1a" instead"#, ) .primary("example.py", "1:1", "1:1", "") .build(); insta::assert_snapshot!(env.render(&diagnostic), @r#" - error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1A" instead + error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1a" instead --> example.py:1:2 | 1 | ␈␛ diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs index a54d2ef5ac..6b621fe0cd 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs @@ -48,7 +48,7 @@ impl Violation for InvalidCharacterBackspace { /// Control characters are displayed differently by different text editors and /// terminals. /// -/// By using the `\x1A` sequence in lieu of the `SUB` control character, the +/// By using the `\x1a` sequence in lieu of the `SUB` control character, the /// string will contain the same value, but will render visibly in all editors. /// /// ## Example @@ -68,7 +68,7 @@ impl Violation for InvalidCharacterSub { #[derive_message_formats] fn message(&self) -> String { - "Invalid unescaped character SUB, use \"\\x1A\" instead".to_string() + "Invalid unescaped character SUB, use \"\\x1a\" instead".to_string() } fn fix_title(&self) -> Option { @@ -83,7 +83,7 @@ impl Violation for InvalidCharacterSub { /// Control characters are displayed differently by different text editors and /// terminals. /// -/// By using the `\x1B` sequence in lieu of the `SUB` control character, the +/// By using the `\x1b` sequence in lieu of the `ESC` control character, the /// string will contain the same value, but will render visibly in all editors. /// /// ## Example @@ -103,7 +103,7 @@ impl Violation for InvalidCharacterEsc { #[derive_message_formats] fn message(&self) -> String { - "Invalid unescaped character ESC, use \"\\x1B\" instead".to_string() + "Invalid unescaped character ESC, use \"\\x1b\" instead".to_string() } fn fix_title(&self) -> Option { @@ -191,7 +191,7 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo _ => return, }; - for (column, match_) in text.match_indices(&['\x08', '\x1A', '\x1B', '\0', '\u{200b}']) { + for (column, match_) in text.match_indices(&['\x08', '\x1a', '\x1b', '\0', '\u{200b}']) { let location = token.start() + TextSize::try_from(column).unwrap(); let c = match_.chars().next().unwrap(); let range = TextRange::at(location, c.text_len()); @@ -209,12 +209,12 @@ pub(crate) fn invalid_string_characters(context: &LintContext, token: &Token, lo "\\b", context.report_diagnostic_if_enabled(InvalidCharacterBackspace, range), ), - '\x1A' => ( - "\\x1A", + '\x1a' => ( + "\\x1a", context.report_diagnostic_if_enabled(InvalidCharacterSub, range), ), - '\x1B' => ( - "\\x1B", + '\x1b' => ( + "\\x1b", context.report_diagnostic_if_enabled(InvalidCharacterEsc, range), ), '\0' => ( diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2512_invalid_characters.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2512_invalid_characters.py.snap index 52cfdf9cced77aa57b7b838d63ae8e0192878dcb..7dd5bc0e6e81992ed23061474470c87c685febae 100644 GIT binary patch delta 130 zcmX@0d_Z|ZFJt1yJ~l?i#K}_`f$Yu7Ok5z29&7pXdMyxg LSr{n*Q4JRW>lrE( delta 130 zcmX@0d_Z|ZFQeneJ~l>1$H`L}f$Yu7Ok5z29&7pXdMyxg LSr{n*Q4JRWTG=QR diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2513_invalid_characters.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2513_invalid_characters.py.snap index 6260152d3df81fd1c8b456ade663ebb705e6356c..31be5ee43bb35a63ccf87c976d13d6a10ef93b70 100644 GIT binary patch delta 154 zcmdm@zD0dPFJsciJ~c+RBy}!hLxstOOj47tFqSYTZT4i+VPs62T*llFkU k`FnthU+{N;6c-9k0&-Y{7BccDsn-G_mxYl65Y=!20D>7Vb^rhX delta 154 zcmdm@zD0dPFQe1OJ~c)*Cv`4kLxstOOj47tFqSYnZT4i+VPtfgT*llFkU k`FnthU+{N;6c-9k0&-Y{7BccXsn-G_mxYl65Y=!20Lv;YHUIzs