diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e59b9c8..0ba1fdf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Fix formatting of index containing brackets string in parentheses ([#992](https://github.com/JohnnyMorganz/StyLua/pull/992)) + ## [2.1.0] - 2025-04-21 ### Added diff --git a/src/formatters/expression.rs b/src/formatters/expression.rs index 112df107..cc69ddb8 100644 --- a/src/formatters/expression.rs +++ b/src/formatters/expression.rs @@ -369,6 +369,7 @@ pub fn is_brackets_string(expression: &Expression) -> bool { .. } ), + Expression::Parentheses { expression, .. } => is_brackets_string(expression), #[cfg(feature = "luau")] Expression::TypeAssertion { expression, .. } => is_brackets_string(expression), _ => false, diff --git a/tests/inputs-luau/string-brackets-index.lua b/tests/inputs-luau/string-brackets-index.lua index 3a8343db..a6c7d420 100644 --- a/tests/inputs-luau/string-brackets-index.lua +++ b/tests/inputs-luau/string-brackets-index.lua @@ -1,5 +1,9 @@ local foo = { [ [[test]] :: test ] = true, + [ ([[foo]]) :: test ] = true, + [ ( [[bar]] ) :: test ] = true, } foo[ [[test]] :: test ] = false +foo[ ([[foo]]) :: test ] = false +foo[ ( [[bar]] ) :: test ] = false diff --git a/tests/inputs/string-brackets-index.lua b/tests/inputs/string-brackets-index.lua index 628f759c..cd6f85d3 100644 --- a/tests/inputs/string-brackets-index.lua +++ b/tests/inputs/string-brackets-index.lua @@ -1,5 +1,11 @@ local foo = { [ [[test]] ] = true, + [([[foo]])] = true, + [( [[bar]] )] = true, + [ ([[baz]]) ] = true, } foo[ [[test]] ] = false +foo[([[foo]])] = true +foo[( [[bar]] )] = true +foo[ ([[baz]]) ] = true diff --git a/tests/snapshots/tests__luau@string-brackets-index.lua.snap b/tests/snapshots/tests__luau@string-brackets-index.lua.snap index 45612df3..378091c3 100644 --- a/tests/snapshots/tests__luau@string-brackets-index.lua.snap +++ b/tests/snapshots/tests__luau@string-brackets-index.lua.snap @@ -5,7 +5,11 @@ input_file: tests/inputs-luau/string-brackets-index.lua --- local foo = { [ [[test]] :: test ] = true, + [ ([[foo]]) :: test ] = true, + [ ([[bar]]) :: test ] = true, } foo[ [[test]] :: test ] = false +foo[ ([[foo]]) :: test ] = false +foo[ ([[bar]]) :: test ] = false diff --git a/tests/snapshots/tests__standard@string-brackets-index.lua.snap b/tests/snapshots/tests__standard@string-brackets-index.lua.snap index 495bafa9..ae4ef45b 100644 --- a/tests/snapshots/tests__standard@string-brackets-index.lua.snap +++ b/tests/snapshots/tests__standard@string-brackets-index.lua.snap @@ -4,7 +4,13 @@ expression: format(&contents) --- local foo = { [ [[test]] ] = true, + [ [[foo]] ] = true, + [ [[bar]] ] = true, + [ [[baz]] ] = true, } foo[ [[test]] ] = false +foo[ [[foo]] ] = true +foo[ [[bar]] ] = true +foo[ [[baz]] ] = true