Skip to content

Commit 3c1c2fa

Browse files
indent return arguments wrapped into parenthesis. fixes #465
1 parent de57013 commit 3c1c2fa

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

lib/hooks/ReturnStatement.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,21 @@ exports.getIndentEdges = function(node, opts) {
3636
return false;
3737
}
3838

39-
var parentheses = expressionParentheses.getParentheses(node.argument);
40-
return parentheses ?
41-
{
42-
startToken: parentheses.opening,
43-
endToken: parentheses.closing
44-
} :
45-
{
46-
startToken: node.startToken.next,
47-
endToken: _tk.isEmpty(node.endToken) ?
48-
_tk.findPrevNonEmpty(node.endToken) :
49-
node.endToken
39+
// handle agument wrapped in parenthesis
40+
var argumentStart = _tk.findNextNonEmpty(node.startToken);
41+
if (argumentStart.value === '(') {
42+
return {
43+
startToken: argumentStart,
44+
endToken: node.endToken.value === ')' ?
45+
node.endToken :
46+
_tk.findPrevNonEmpty(_tk.findPrev(node.endToken, ')'))
5047
};
48+
}
49+
50+
return {
51+
startToken: node.startToken.next,
52+
endToken: _tk.isEmpty(node.endToken) ?
53+
_tk.findPrevNonEmpty(node.endToken) :
54+
node.endToken
55+
};
5156
};

test/compare/default/function_declaration-in.js

+12
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,15 @@ function test(arr) {
119119
// #458
120120
function flow(one: OneType<string>, two: TwoTypes<string, string> , three: string) {
121121
}
122+
123+
// #465
124+
function indentReturnParentheses() {
125+
if (bar) {
126+
return (
127+
bar
128+
)
129+
}
130+
return (
131+
dolorAmet
132+
);
133+
}

test/compare/default/function_declaration-out.js

+12
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ function test(arr) {
130130
// #458
131131
function flow(one: OneType<string>, two: TwoTypes<string, string>, three: string) {
132132
}
133+
134+
// #465
135+
function indentReturnParentheses() {
136+
if (bar) {
137+
return (
138+
bar
139+
)
140+
}
141+
return (
142+
dolorAmet
143+
);
144+
}

0 commit comments

Comments
 (0)