Skip to content

Commit

Permalink
Don't collapse compound type field if it contains comments (#906)
Browse files Browse the repository at this point in the history
* Add test case

* Don't collapse compound type field if it contains types
  • Loading branch information
JohnnyMorganz authored Oct 26, 2024
1 parent f78c063 commit e4952b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/formatters/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand Down
6 changes: 6 additions & 0 deletions tests/inputs-luau/type-tables-comments-2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- https://github.com/JohnnyMorganz/StyLua/issues/893
type Foo = {
Status: "loading" -- loading
| "error" -- error
| "success" -- success
}
11 changes: 11 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e4952b1

Please sign in to comment.