Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Options {
indentCount: number;
useTabs: boolean;
linebreakMultipleAssignments: boolean;
inlineFunctionCalls: boolean;
quotemark: Quotemark;
writeMode: WriteMode;
}
Expand All @@ -23,6 +24,7 @@ export const defaultOptions: Options = {
indentCount: 4,
useTabs: false,
linebreakMultipleAssignments: false,
inlineFunctionCalls: true,
quotemark: 'double',
writeMode: WriteMode.StdOut
};
Expand Down
27 changes: 18 additions & 9 deletions src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ function printNodeNoParens(path: FastPath, options: Options, print: PrintFn) {
const canBreakLine = node.init.some(n =>
n != null &&
n.type !== 'TableConstructorExpression' &&
n.type !== 'FunctionDeclaration'
n.type !== 'FunctionDeclaration' &&
n.type !== 'CallExpression'
);

return group(
Expand Down Expand Up @@ -491,17 +492,25 @@ function printNodeNoParens(path: FastPath, options: Options, print: PrintFn) {
// last argument is a table, it would be beneficial to break on the table, rather than breaking the entire
// argument list.

const callExpressionSpacing = options.inlineFunctionCalls ?
[
'(',
concat([join(concat([',', ' ']), printedCallExpressionArgs)]),
')'
] :
[
'(',
indent(
concat([softline, join(concat([',', line]), printedCallExpressionArgs)])
),
softline,
')'
];

return concat([
path.call(print, 'base'),
group(
concat([
'(',
indent(
concat([softline, join(concat([',', line]), printedCallExpressionArgs)])
),
softline,
')'
]),
concat(callExpressionSpacing),
printedCallExpressionArgs.some(willBreak)
)
]);
Expand Down
19 changes: 14 additions & 5 deletions test/function/__snapshots__/function.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ end

local ok, err = pcall(foo)

local ok, err =
pcall(
function()
end
)
local ok, err = pcall(function()
end)

local result = foo({1, 2, 3}, function(value)
return 1 % 2 == 0
end)

local result = foo({1, 2, 3}, \\"helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\\", \\"hi\\", true, nil, function(
value)
return 1 % 2 == 0
end)

local result = foo(function(value)
end, {1, 2, 3}, \\"helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\\")
"
`;
6 changes: 6 additions & 0 deletions test/function/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ end
local ok, err = pcall(foo)

local ok, err = pcall(function() end)

local result = foo({1, 2, 3}, function(value) return 1 % 2 == 0 end)

local result = foo({1, 2, 3}, "helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", 'hi', true, nil, function(value) return 1 % 2 == 0 end)

local result = foo(function(value) end, {1, 2, 3}, "helloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
29 changes: 9 additions & 20 deletions test/linewrap/__snapshots__/linewrap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,26 @@ end
local a,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
c = foo()
print(
a,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
c
)
print(a, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, c)

local a,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc =
foo()
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = foo()

local a, b, c, d, e, f = emptyFunction()

local a, b, c, d, e, f = emptyFunction(), emptyFunction()

local a, b, c, d, e, f = emptyFunction(), emptyFunction(), emptyFunction()

local a, b, c, d, e, f =
emptyFunction(),
emptyFunction(
function()
return true
end
)

local a, b, c, d, e, f =
emptyFunction(
function()
local a, b, c, d, e, f = emptyFunction(),
emptyFunction(function()
return true
end
)
end)

local a, b, c, d, e, f = emptyFunction(function()
return true
end)

local function object()
local self = {}
Expand Down
2 changes: 1 addition & 1 deletion test/linewrap/assignment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end
local a, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, c = foo()
print(a, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, c)

local a, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = foo()
local a, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = foo()

local a, b, c, d, e, f = emptyFunction()

Expand Down