From 46ce1efff351f991d8112e5a4a2a047f8fd5c95b Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 12 Dec 2025 17:18:15 -0800 Subject: [PATCH] comment --- .../flake8_implicit_str_concat/ISC004.py | 18 +++ .../rules/collection_literal.rs | 14 ++- ...t_str_concat__tests__ISC004_ISC004.py.snap | 108 +++++++++++++++++- 3 files changed, 135 insertions(+), 5 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC004.py b/crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC004.py index edd736f41b..974667544a 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC004.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC004.py @@ -26,6 +26,24 @@ facts = { ), } +facts = ( + "Octopuses have three hearts." + # Missing comma here. + "Honey never spoils.", +) + +facts = [ + "Octopuses have three hearts." + # Missing comma here. + "Honey never spoils.", +] + +facts = { + "Octopuses have three hearts." + # Missing comma here. + "Honey never spoils.", +} + facts = ( ( "Clarinets are made almost entirely out of wood from the mpingo tree." diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs index a3e8179f9d..db5449e824 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/collection_literal.rs @@ -4,7 +4,7 @@ use ruff_python_ast::{Expr, StringLike}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; -use crate::Violation; +use crate::{Edit, Fix, FixAvailability, Violation}; /// ## What it does /// Checks for implicitly concatenated strings inside list, tuple, and set literals. @@ -50,10 +50,16 @@ use crate::Violation; pub(crate) struct ImplicitStringConcatenationInCollectionLiteral; impl Violation for ImplicitStringConcatenationInCollectionLiteral { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always; + #[derive_message_formats] fn message(&self) -> String { "Implicit string concatenation in collection literal; did you forget a comma?".to_string() } + + fn fix_title(&self) -> Option { + Some("Wrap implicitly concatenated strings in parentheses".to_string()) + } } /// ISC004 @@ -75,9 +81,13 @@ pub(crate) fn implicit_string_concatenation_in_collection_literal( continue; } - checker.report_diagnostic( + let mut diagnostic = checker.report_diagnostic( ImplicitStringConcatenationInCollectionLiteral, string_like.range(), ); + diagnostic.set_fix(Fix::safe_edits( + Edit::insertion("(".to_string(), string_like.range().start()), + [Edit::insertion(")".to_string(), string_like.range().end())], + )); } } diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/snapshots/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC004_ISC004.py.snap b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/snapshots/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC004_ISC004.py.snap index f54bea9e2a..cb063f8c7a 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/snapshots/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC004_ISC004.py.snap +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/snapshots/ruff_linter__rules__flake8_implicit_str_concat__tests__ISC004_ISC004.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs --- -ISC004 Implicit string concatenation in collection literal; did you forget a comma? +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? --> ISC004.py:4:5 | 2 | "Lobsters have blue blood.", @@ -11,8 +11,19 @@ ISC004 Implicit string concatenation in collection literal; did you forget a com | |______________________________________________________________^ 6 | ) | +help: Wrap implicitly concatenated strings in parentheses +1 | facts = ( +2 | "Lobsters have blue blood.", +3 | "The liver is the only human organ that can fully regenerate itself.", + - "Clarinets are made almost entirely out of wood from the mpingo tree." + - "In 1971, astronaut Alan Shepard played golf on the moon.", +4 + ("Clarinets are made almost entirely out of wood from the mpingo tree." +5 + "In 1971, astronaut Alan Shepard played golf on the moon."), +6 | ) +7 | +8 | facts = [ -ISC004 Implicit string concatenation in collection literal; did you forget a comma? +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? --> ISC004.py:11:5 | 9 | "Lobsters have blue blood.", @@ -22,8 +33,19 @@ ISC004 Implicit string concatenation in collection literal; did you forget a com | |______________________________________________________________^ 13 | ] | +help: Wrap implicitly concatenated strings in parentheses +8 | facts = [ +9 | "Lobsters have blue blood.", +10 | "The liver is the only human organ that can fully regenerate itself.", + - "Clarinets are made almost entirely out of wood from the mpingo tree." + - "In 1971, astronaut Alan Shepard played golf on the moon.", +11 + ("Clarinets are made almost entirely out of wood from the mpingo tree." +12 + "In 1971, astronaut Alan Shepard played golf on the moon."), +13 | ] +14 | +15 | facts = { -ISC004 Implicit string concatenation in collection literal; did you forget a comma? +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? --> ISC004.py:18:5 | 16 | "Lobsters have blue blood.", @@ -33,3 +55,83 @@ ISC004 Implicit string concatenation in collection literal; did you forget a com | |______________________________________________________________^ 20 | } | +help: Wrap implicitly concatenated strings in parentheses +15 | facts = { +16 | "Lobsters have blue blood.", +17 | "The liver is the only human organ that can fully regenerate itself.", + - "Clarinets are made almost entirely out of wood from the mpingo tree." + - "In 1971, astronaut Alan Shepard played golf on the moon.", +18 + ("Clarinets are made almost entirely out of wood from the mpingo tree." +19 + "In 1971, astronaut Alan Shepard played golf on the moon."), +20 | } +21 | +22 | facts = { + +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? + --> ISC004.py:30:5 + | +29 | facts = ( +30 | / "Octopuses have three hearts." +31 | | # Missing comma here. +32 | | "Honey never spoils.", + | |_________________________^ +33 | ) + | +help: Wrap implicitly concatenated strings in parentheses +27 | } +28 | +29 | facts = ( + - "Octopuses have three hearts." +30 + ("Octopuses have three hearts." +31 | # Missing comma here. + - "Honey never spoils.", +32 + "Honey never spoils."), +33 | ) +34 | +35 | facts = [ + +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? + --> ISC004.py:36:5 + | +35 | facts = [ +36 | / "Octopuses have three hearts." +37 | | # Missing comma here. +38 | | "Honey never spoils.", + | |_________________________^ +39 | ] + | +help: Wrap implicitly concatenated strings in parentheses +33 | ) +34 | +35 | facts = [ + - "Octopuses have three hearts." +36 + ("Octopuses have three hearts." +37 | # Missing comma here. + - "Honey never spoils.", +38 + "Honey never spoils."), +39 | ] +40 | +41 | facts = { + +ISC004 [*] Implicit string concatenation in collection literal; did you forget a comma? + --> ISC004.py:42:5 + | +41 | facts = { +42 | / "Octopuses have three hearts." +43 | | # Missing comma here. +44 | | "Honey never spoils.", + | |_________________________^ +45 | } + | +help: Wrap implicitly concatenated strings in parentheses +39 | ] +40 | +41 | facts = { + - "Octopuses have three hearts." +42 + ("Octopuses have three hearts." +43 | # Missing comma here. + - "Honey never spoils.", +44 + "Honey never spoils."), +45 | } +46 | +47 | facts = (