diff --git a/crates/ruff/resources/test/fixtures/flake8_commas/COM81.py b/crates/ruff/resources/test/fixtures/flake8_commas/COM81.py index dc6db3a3c2889..f76059e98d095 100644 --- a/crates/ruff/resources/test/fixtures/flake8_commas/COM81.py +++ b/crates/ruff/resources/test/fixtures/flake8_commas/COM81.py @@ -631,3 +631,11 @@ def foo( the_first_one = next( (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket ) + +foo = namedtuple( + name="foo", + status="bar", + message="sfdsdfsdgs fsdfsdf output!dsfdfsdjkg ghfskdjghkdssd sd fsdf s\n"[ + :20 + ], +) diff --git a/crates/ruff/src/rules/flake8_commas/rules.rs b/crates/ruff/src/rules/flake8_commas/rules.rs index 079ad514df509..eaee333c3ca84 100644 --- a/crates/ruff/src/rules/flake8_commas/rules.rs +++ b/crates/ruff/src/rules/flake8_commas/rules.rs @@ -27,6 +27,7 @@ enum TokenType { Def, Lambda, Colon, + String, } /// Simplified token specialized for the task. @@ -55,6 +56,7 @@ impl<'tok> Token<'tok> { // Import treated like a function. Tok::Import => TokenType::Named, Tok::Name { .. } => TokenType::Named, + Tok::String { .. } => TokenType::String, Tok::Comma => TokenType::Comma, Tok::Lpar => TokenType::OpeningBracket, Tok::Lsqb => TokenType::OpeningSquareBracket, @@ -265,7 +267,7 @@ pub(crate) fn trailing_commas( } }, TokenType::OpeningSquareBracket => match prev.type_ { - TokenType::ClosingBracket | TokenType::Named => { + TokenType::ClosingBracket | TokenType::Named | TokenType::String => { stack.push(Context::new(ContextType::Subscript)); } _ => { diff --git a/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap b/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap index 0089753e67694..e7b889c36d964 100644 --- a/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap +++ b/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap @@ -936,5 +936,7 @@ COM81.py:632:42: COM812 [*] Trailing comma missing 632 |- (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket 632 |+ (i for i in range(10) if i // 2 == 0), # COM812 fix should include the final bracket 633 633 | ) +634 634 | +635 635 | foo = namedtuple(