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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added flag `--no-ignore-vcs` to continue formatting files listed in a `.gitignore` file, instead of skipping over them ([#895](https://github.com/JohnnyMorganz/StyLua/issues/895))

### Fixed

- Fixed syntax error in output when a single-line comment appears between an index suffix and a table call argument, e.g. `foo.bar -- comment { }` ([#873](https://github.com/JohnnyMorganz/StyLua/issues/873))

## [2.3.1] - 2025-11-01

### Fixed
Expand Down
10 changes: 9 additions & 1 deletion src/formatters/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,18 @@ pub fn format_function_call(

let mut suffix = format_suffix(ctx, suffix, current_shape, ambiguous_next_suffix);

// Check if the previous suffix has trailing single-line comments.
// If it does, we MUST hang the AnonymousCall to avoid the opening parenthesis being commented out
let previous_suffix_has_trailing_singleline_comment = formatted_suffixes
.last()
.map(|s: &Suffix| s.has_trailing_comments(CommentSearch::Single))
.unwrap_or(false);

// Hang the call, but don't hang if the previous suffix was an index and this is an anonymous call, i.e. `.foo()`
if will_hang
&& !(previous_suffix_was_index
&& matches!(suffix, Suffix::Call(Call::AnonymousCall(_))))
&& matches!(suffix, Suffix::Call(Call::AnonymousCall(_)))
&& !previous_suffix_has_trailing_singleline_comment)
{
suffix = trivia_util::prepend_newline_indent(ctx, &suffix, current_shape);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/inputs/hang-call-chain-comments-4.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- https://github.com/JohnnyMorganz/StyLua/issues/873

x = a.b -- comment
{
y
}

console.dialog = iup.dialog
{
iup.hbox -- use it to inherit margins
{
console.prompt,
},
title = "Command:",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::Lua51)"
input_file: tests/inputs/hang-call-chain-comments-4.lua
---
-- https://github.com/JohnnyMorganz/StyLua/issues/873

x = a
.b -- comment
({
y,
})

console.dialog = iup.dialog({
iup
.hbox -- use it to inherit margins
({
console.prompt,
}),
title = "Command:",
})
Loading