From a1ee6d28cead73978c1bb58848963897124f4834 Mon Sep 17 00:00:00 2001 From: T-256 <132141463+T-256@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:11:51 +0330 Subject: [PATCH] `UP018`: Improve Fix message (#7913) ## Summary closes https://github.com/astral-sh/ruff/issues/7912 ## Test Plan --- .../rules/pyupgrade/rules/native_literals.rs | 10 +++---- ...er__rules__pyupgrade__tests__UP018.py.snap | 30 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index b45ef714bbebe..867225c746942 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -117,11 +117,11 @@ impl AlwaysFixableViolation for NativeLiterals { fn fix_title(&self) -> String { let NativeLiterals { literal_type } = self; match literal_type { - LiteralType::Str => "Replace with empty string".to_string(), - LiteralType::Bytes => "Replace with empty bytes".to_string(), - LiteralType::Int => "Replace with 0".to_string(), - LiteralType::Float => "Replace with 0.0".to_string(), - LiteralType::Bool => "Replace with `False`".to_string(), + LiteralType::Str => "Replace with string literal".to_string(), + LiteralType::Bytes => "Replace with bytes literal".to_string(), + LiteralType::Int => "Replace with integer literal".to_string(), + LiteralType::Float => "Replace with float literal".to_string(), + LiteralType::Bool => "Replace with boolean literal".to_string(), } } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP018.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP018.py.snap index a43a4e9b9f22d..cdd56ab5c14e8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP018.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP018.py.snap @@ -9,7 +9,7 @@ UP018.py:37:1: UP018 [*] Unnecessary `str` call (rewrite as a literal) 38 | str("foo") 39 | str(""" | - = help: Replace with empty string + = help: Replace with string literal ℹ Fix 34 34 | int().denominator @@ -30,7 +30,7 @@ UP018.py:38:1: UP018 [*] Unnecessary `str` call (rewrite as a literal) 39 | str(""" 40 | foo""") | - = help: Replace with empty string + = help: Replace with string literal ℹ Fix 35 35 | @@ -52,7 +52,7 @@ UP018.py:39:1: UP018 [*] Unnecessary `str` call (rewrite as a literal) 41 | bytes() 42 | bytes(b"foo") | - = help: Replace with empty string + = help: Replace with string literal ℹ Fix 36 36 | # These become string or byte literals @@ -75,7 +75,7 @@ UP018.py:41:1: UP018 [*] Unnecessary `bytes` call (rewrite as a literal) 42 | bytes(b"foo") 43 | bytes(b""" | - = help: Replace with empty bytes + = help: Replace with bytes literal ℹ Fix 38 38 | str("foo") @@ -96,7 +96,7 @@ UP018.py:42:1: UP018 [*] Unnecessary `bytes` call (rewrite as a literal) 43 | bytes(b""" 44 | foo""") | - = help: Replace with empty bytes + = help: Replace with bytes literal ℹ Fix 39 39 | str(""" @@ -118,7 +118,7 @@ UP018.py:43:1: UP018 [*] Unnecessary `bytes` call (rewrite as a literal) 45 | f"{str()}" 46 | int() | - = help: Replace with empty bytes + = help: Replace with bytes literal ℹ Fix 40 40 | foo""") @@ -141,7 +141,7 @@ UP018.py:45:4: UP018 [*] Unnecessary `str` call (rewrite as a literal) 46 | int() 47 | int(1) | - = help: Replace with empty string + = help: Replace with string literal ℹ Fix 42 42 | bytes(b"foo") @@ -162,7 +162,7 @@ UP018.py:46:1: UP018 [*] Unnecessary `int` call (rewrite as a literal) 47 | int(1) 48 | float() | - = help: Replace with 0 + = help: Replace with integer literal ℹ Fix 43 43 | bytes(b""" @@ -183,7 +183,7 @@ UP018.py:47:1: UP018 [*] Unnecessary `int` call (rewrite as a literal) 48 | float() 49 | float(1.0) | - = help: Replace with 0 + = help: Replace with integer literal ℹ Fix 44 44 | foo""") @@ -204,7 +204,7 @@ UP018.py:48:1: UP018 [*] Unnecessary `float` call (rewrite as a literal) 49 | float(1.0) 50 | bool() | - = help: Replace with 0.0 + = help: Replace with float literal ℹ Fix 45 45 | f"{str()}" @@ -225,7 +225,7 @@ UP018.py:49:1: UP018 [*] Unnecessary `float` call (rewrite as a literal) 50 | bool() 51 | bool(True) | - = help: Replace with 0.0 + = help: Replace with float literal ℹ Fix 46 46 | int() @@ -246,7 +246,7 @@ UP018.py:50:1: UP018 [*] Unnecessary `bool` call (rewrite as a literal) 51 | bool(True) 52 | bool(False) | - = help: Replace with `False` + = help: Replace with boolean literal ℹ Fix 47 47 | int(1) @@ -266,7 +266,7 @@ UP018.py:51:1: UP018 [*] Unnecessary `bool` call (rewrite as a literal) | ^^^^^^^^^^ UP018 52 | bool(False) | - = help: Replace with `False` + = help: Replace with boolean literal ℹ Fix 48 48 | float() @@ -287,7 +287,7 @@ UP018.py:52:1: UP018 [*] Unnecessary `bool` call (rewrite as a literal) 53 | 54 | # These become a literal but retain parentheses | - = help: Replace with `False` + = help: Replace with boolean literal ℹ Fix 49 49 | float(1.0) @@ -305,7 +305,7 @@ UP018.py:55:1: UP018 [*] Unnecessary `int` call (rewrite as a literal) 55 | int(1).denominator | ^^^^^^ UP018 | - = help: Replace with 0 + = help: Replace with integer literal ℹ Fix 52 52 | bool(False)