follow up

This commit is contained in:
hauntsaninja 2025-12-16 12:58:00 -08:00
parent cce85bc95e
commit 723f590ea4
2 changed files with 26 additions and 8 deletions

View File

@ -45,6 +45,11 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ), /// ),
/// ) /// )
/// ``` /// ```
///
/// ## Fix safety
/// The fix is safe in that it does not change the semantics of your code.
/// However, the issue is that you may often want to change semantics
/// by adding a missing comma.
#[derive(ViolationMetadata)] #[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.14.9")] #[violation_metadata(preview_since = "0.14.9")]
pub(crate) struct ImplicitStringConcatenationInCollectionLiteral; pub(crate) struct ImplicitStringConcatenationInCollectionLiteral;
@ -54,7 +59,7 @@ impl Violation for ImplicitStringConcatenationInCollectionLiteral {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
"Unparenthesized implicit string concatenation in collection; did you forget a comma?" "Unparenthesized implicit string concatenation in collection"
.to_string() .to_string()
} }
@ -90,7 +95,8 @@ pub(crate) fn implicit_string_concatenation_in_collection_literal(
ImplicitStringConcatenationInCollectionLiteral, ImplicitStringConcatenationInCollectionLiteral,
string_like.range(), string_like.range(),
); );
diagnostic.set_fix(Fix::safe_edits( diagnostic.help("Did you forget a comma?");
diagnostic.set_fix(Fix::unsafe_edits(
Edit::insertion("(".to_string(), string_like.range().start()), Edit::insertion("(".to_string(), string_like.range().start()),
[Edit::insertion(")".to_string(), string_like.range().end())], [Edit::insertion(")".to_string(), string_like.range().end())],
)); ));

View File

@ -1,7 +1,7 @@
--- ---
source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs
--- ---
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:4:5 --> ISC004.py:4:5
| |
2 | "Lobsters have blue blood.", 2 | "Lobsters have blue blood.",
@ -12,6 +12,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
6 | ) 6 | )
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
1 | facts = ( 1 | facts = (
2 | "Lobsters have blue blood.", 2 | "Lobsters have blue blood.",
3 | "The liver is the only human organ that can fully regenerate itself.", 3 | "The liver is the only human organ that can fully regenerate itself.",
@ -22,8 +23,9 @@ help: Wrap implicitly concatenated strings in parentheses
6 | ) 6 | )
7 | 7 |
8 | facts = [ 8 | facts = [
note: This is an unsafe fix and may change runtime behavior
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:11:5 --> ISC004.py:11:5
| |
9 | "Lobsters have blue blood.", 9 | "Lobsters have blue blood.",
@ -34,6 +36,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
13 | ] 13 | ]
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
8 | facts = [ 8 | facts = [
9 | "Lobsters have blue blood.", 9 | "Lobsters have blue blood.",
10 | "The liver is the only human organ that can fully regenerate itself.", 10 | "The liver is the only human organ that can fully regenerate itself.",
@ -44,8 +47,9 @@ help: Wrap implicitly concatenated strings in parentheses
13 | ] 13 | ]
14 | 14 |
15 | facts = { 15 | facts = {
note: This is an unsafe fix and may change runtime behavior
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:18:5 --> ISC004.py:18:5
| |
16 | "Lobsters have blue blood.", 16 | "Lobsters have blue blood.",
@ -56,6 +60,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
20 | } 20 | }
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
15 | facts = { 15 | facts = {
16 | "Lobsters have blue blood.", 16 | "Lobsters have blue blood.",
17 | "The liver is the only human organ that can fully regenerate itself.", 17 | "The liver is the only human organ that can fully regenerate itself.",
@ -66,8 +71,9 @@ help: Wrap implicitly concatenated strings in parentheses
20 | } 20 | }
21 | 21 |
22 | facts = { 22 | facts = {
note: This is an unsafe fix and may change runtime behavior
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:30:5 --> ISC004.py:30:5
| |
29 | facts = ( 29 | facts = (
@ -78,6 +84,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
33 | ) 33 | )
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
27 | } 27 | }
28 | 28 |
29 | facts = ( 29 | facts = (
@ -89,8 +96,9 @@ help: Wrap implicitly concatenated strings in parentheses
33 | ) 33 | )
34 | 34 |
35 | facts = [ 35 | facts = [
note: This is an unsafe fix and may change runtime behavior
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:36:5 --> ISC004.py:36:5
| |
35 | facts = [ 35 | facts = [
@ -101,6 +109,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
39 | ] 39 | ]
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
33 | ) 33 | )
34 | 34 |
35 | facts = [ 35 | facts = [
@ -112,8 +121,9 @@ help: Wrap implicitly concatenated strings in parentheses
39 | ] 39 | ]
40 | 40 |
41 | facts = { 41 | facts = {
note: This is an unsafe fix and may change runtime behavior
ISC004 [*] Unparenthesized implicit string concatenation in collection; did you forget a comma? ISC004 [*] Unparenthesized implicit string concatenation in collection
--> ISC004.py:42:5 --> ISC004.py:42:5
| |
41 | facts = { 41 | facts = {
@ -124,6 +134,7 @@ ISC004 [*] Unparenthesized implicit string concatenation in collection; did you
45 | } 45 | }
| |
help: Wrap implicitly concatenated strings in parentheses help: Wrap implicitly concatenated strings in parentheses
help: Did you forget a comma?
39 | ] 39 | ]
40 | 40 |
41 | facts = { 41 | facts = {
@ -135,3 +146,4 @@ help: Wrap implicitly concatenated strings in parentheses
45 | } 45 | }
46 | 46 |
47 | facts = ( 47 | facts = (
note: This is an unsafe fix and may change runtime behavior