Skip to content

Commit

Permalink
indent return arguments wrapped into parenthesis. fixes #465
Browse files Browse the repository at this point in the history
  • Loading branch information
millermedeiros committed Dec 22, 2016
1 parent de57013 commit 3c1c2fa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/hooks/ReturnStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ exports.getIndentEdges = function(node, opts) {
return false;
}

var parentheses = expressionParentheses.getParentheses(node.argument);
return parentheses ?
{
startToken: parentheses.opening,
endToken: parentheses.closing
} :
{
startToken: node.startToken.next,
endToken: _tk.isEmpty(node.endToken) ?
_tk.findPrevNonEmpty(node.endToken) :
node.endToken
// handle agument wrapped in parenthesis
var argumentStart = _tk.findNextNonEmpty(node.startToken);
if (argumentStart.value === '(') {
return {
startToken: argumentStart,
endToken: node.endToken.value === ')' ?
node.endToken :
_tk.findPrevNonEmpty(_tk.findPrev(node.endToken, ')'))
};
}

return {
startToken: node.startToken.next,
endToken: _tk.isEmpty(node.endToken) ?
_tk.findPrevNonEmpty(node.endToken) :
node.endToken
};
};
12 changes: 12 additions & 0 deletions test/compare/default/function_declaration-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,15 @@ function test(arr) {
// #458
function flow(one: OneType<string>, two: TwoTypes<string, string> , three: string) {
}

// #465
function indentReturnParentheses() {
if (bar) {
return (
bar
)
}
return (
dolorAmet
);
}
12 changes: 12 additions & 0 deletions test/compare/default/function_declaration-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,15 @@ function test(arr) {
// #458
function flow(one: OneType<string>, two: TwoTypes<string, string>, three: string) {
}

// #465
function indentReturnParentheses() {
if (bar) {
return (
bar
)
}
return (
dolorAmet
);
}

0 comments on commit 3c1c2fa

Please sign in to comment.