Skip to content

Commit ee290b0

Browse files
Don't put function definition parentheses on multiple lines when no parens (#838)
* Add test case * Don't put on multiple lines * Update snapshots and changelog
1 parent 987c489 commit ee290b0

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

CHANGELOG.md

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

1718
## [0.19.1] - 2023-11-15
1819

src/formatters/functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ fn should_parameters_format_multiline(
572572
const PARENS_LEN: usize = "()".len();
573573
const SINGLELINE_END_LEN: usize = " end".len();
574574

575+
if function_body.parameters().is_empty() {
576+
return false;
577+
}
578+
575579
// Check the length of the parameters. We need to format them first onto a single line to check if required
576580
let mut line_length = format_singleline_parameters(ctx, function_body, shape)
577581
.to_string()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- https://github.com/JohnnyMorganz/StyLua/issues/830
2+
local a_very_long_variable_name_given_that_is_bigger_than_width_upper_limit_but_unfortunately_can_not_be_made_shorter = function()
3+
print("Hello")
4+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: tests/tests.rs
3+
expression: format(&contents)
4+
input_file: tests/inputs/function-definition-multiline-2.lua
5+
---
6+
-- https://github.com/JohnnyMorganz/StyLua/issues/830
7+
local a_very_long_variable_name_given_that_is_bigger_than_width_upper_limit_but_unfortunately_can_not_be_made_shorter = function()
8+
print("Hello")
9+
end
10+

0 commit comments

Comments
 (0)