Skip to content
Open
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 @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed goto not being recognised for LuaJIT ([#986](https://github.com/JohnnyMorganz/StyLua/issues/986))
- Fixed semicolon removed after a statement ending with an if-expression leading to ambiguous syntax when the next line begins with parentheses ([#1010](https://github.com/JohnnyMorganz/StyLua/issues/1010))
- Luau: Fixed malformed formatting when there is a comment after a type specifier in a local assignment ([#995](https://github.com/JohnnyMorganz/StyLua/issues/995))
- Fixed malformed formatting when a binary expression inside of a function call with comments around the operators is incorrectly collapsed onto one line ([#996](https://github.com/JohnnyMorganz/StyLua/issues/996))

## [2.1.0] - 2025-04-21

Expand Down
4 changes: 3 additions & 1 deletion src/formatters/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,13 @@ fn function_args_contains_comments(
true
} else {
arguments.pairs().any(|argument| {
// Leading / Trailing trivia of expression (ignore inline comments)
// Leading / Trailing trivia of expression
argument.value().leading_trivia()
.iter()
.chain(argument.value().trailing_trivia().iter())
.any(function_trivia_contains_comments)
// Inline comments that will force hanging
|| argument.value().has_inline_comments()
// Punctuation contains comments
|| argument
.punctuation()
Expand Down
10 changes: 10 additions & 0 deletions tests/inputs/hang-binop-comments-3.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- https://github.com/JohnnyMorganz/StyLua/issues/996

local function f()
local a = "ab"
a = a:gsub("a".. -- "
'b', function() return "c" end)
print(a)
end

f()
20 changes: 20 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::Lua51)"
input_file: tests/inputs/hang-binop-comments-3.lua
---
-- https://github.com/JohnnyMorganz/StyLua/issues/996

local function f()
local a = "ab"
a = a:gsub(
"a" -- "
.. "b",
function()
return "c"
end
)
print(a)
end

f()
Loading