Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed missing space when table is inside of Luau interpolated string expression (`{{` is invalid syntax)
- The CLI tool will now only write files if the contents differ, and not modify if no change (#827)
- Fixed parentheses around a Luau compound type inside of a type table indexer being removed causing a syntax error (#828)
- Fixed function body parentheses being placed on multiple lines unnecessarily when there are no parameters (#830)

## [0.19.1] - 2023-11-15

Expand Down
4 changes: 4 additions & 0 deletions src/formatters/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ fn should_parameters_format_multiline(
const PARENS_LEN: usize = "()".len();
const SINGLELINE_END_LEN: usize = " end".len();

if function_body.parameters().is_empty() {
return false;
}

// Check the length of the parameters. We need to format them first onto a single line to check if required
let mut line_length = format_singleline_parameters(ctx, function_body, shape)
.to_string()
Expand Down
4 changes: 4 additions & 0 deletions tests/inputs/function-definition-multiline-2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- https://github.com/JohnnyMorganz/StyLua/issues/830
local a_very_long_variable_name_given_that_is_bigger_than_width_upper_limit_but_unfortunately_can_not_be_made_shorter = function()
print("Hello")
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: tests/tests.rs
expression: format(&contents)
input_file: tests/inputs/function-definition-multiline-2.lua
---
-- https://github.com/JohnnyMorganz/StyLua/issues/830
local a_very_long_variable_name_given_that_is_bigger_than_width_upper_limit_but_unfortunately_can_not_be_made_shorter = function()
print("Hello")
end