diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a6162f1..94dcb899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed formatting of method call chain when there is a comment between the colon token `:` and the function name ([#890](https://github.com/JohnnyMorganz/StyLua/issues/890)) - Luau: Fixed incorrect removal of semicolon before compound assignment with parentheses leading to ambiguous syntax error ([#885](https://github.com/JohnnyMorganz/StyLua/issues/885)) +- Luau: Fixed incorrect collapsing of union/intersection type value with comments in a type table leading to a syntax error ([#893](https://github.com/JohnnyMorganz/StyLua/issues/893)) ## [0.20.0] - 2024-01-20 diff --git a/src/formatters/luau.rs b/src/formatters/luau.rs index 5c7e56e8..f0698c05 100644 --- a/src/formatters/luau.rs +++ b/src/formatters/luau.rs @@ -861,7 +861,10 @@ pub fn format_type_field( if let TableType::MultiLine = table_type { // If still over budget, hang the type - if can_hang_type(type_field.value()) && shape.test_over_budget(&value) { + if can_hang_type(type_field.value()) + && (should_hang_type(type_field.value(), CommentSearch::Single) + || shape.test_over_budget(&value)) + { value = hang_type_info(ctx, type_field.value(), TypeInfoContext::new(), shape, 1) }; diff --git a/tests/inputs-luau/type-tables-comments-2.lua b/tests/inputs-luau/type-tables-comments-2.lua new file mode 100644 index 00000000..7aaa0215 --- /dev/null +++ b/tests/inputs-luau/type-tables-comments-2.lua @@ -0,0 +1,6 @@ +-- https://github.com/JohnnyMorganz/StyLua/issues/893 +type Foo = { + Status: "loading" -- loading + | "error" -- error + | "success" -- success +} \ No newline at end of file diff --git a/tests/snapshots/tests__luau@type-tables-comments-2.lua.snap b/tests/snapshots/tests__luau@type-tables-comments-2.lua.snap new file mode 100644 index 00000000..85674d25 --- /dev/null +++ b/tests/snapshots/tests__luau@type-tables-comments-2.lua.snap @@ -0,0 +1,11 @@ +--- +source: tests/tests.rs +expression: format(&contents) +input_file: tests/inputs-luau/type-tables-comments-2.lua +--- +-- https://github.com/JohnnyMorganz/StyLua/issues/893 +type Foo = { + Status: "loading" -- loading + | "error" -- error + | "success", -- success +}