Skip to content

Commit

Permalink
Update: Ensure indent handles nested functions correctly (fixes #7249
Browse files Browse the repository at this point in the history
…) (#7265)
  • Loading branch information
not-an-aardvark authored and nzakas committed Sep 30, 2016
1 parent c36d842 commit 332d213
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/indent.js
Expand Up @@ -939,7 +939,7 @@ module.exports = {
if (options.FunctionDeclaration.parameters === "first" && node.params.length) {
checkNodesIndent(node.params.slice(1), node.params[0].loc.start.column);
} else if (options.FunctionDeclaration.parameters !== null) {
checkNodesIndent(node.params, indentSize * options.FunctionDeclaration.parameters);
checkNodesIndent(node.params, getNodeIndent(node).goodChar + indentSize * options.FunctionDeclaration.parameters);
}
},

Expand All @@ -950,7 +950,7 @@ module.exports = {
if (options.FunctionExpression.parameters === "first" && node.params.length) {
checkNodesIndent(node.params.slice(1), node.params[0].loc.start.column);
} else if (options.FunctionExpression.parameters !== null) {
checkNodesIndent(node.params, indentSize * options.FunctionExpression.parameters);
checkNodesIndent(node.params, getNodeIndent(node).goodChar + indentSize * options.FunctionExpression.parameters);
}
}
};
Expand Down
93 changes: 93 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -1561,13 +1561,42 @@ ruleTester.run("indent", rule, {
"}",
options: [2]
},
{
code:
"function foo() {\n" +
" function bar() {\n" +
" baz();\n" +
" }\n" +
"}",
options: [2, {FunctionDeclaration: {body: 1}}]
},
{
code:
"function foo() {\n" +
" bar();\n" +
" \t\t}",
options: [2]
},
{
code:
"function foo() {\n" +
" function bar(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" }\n" +
"}",
options: [2, {FunctionDeclaration: {body: 1, parameters: 2}}]
},
{
code:
"function foo() {\n" +
" var bar = function(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" };\n" +
"}",
options: [2, {FunctionExpression: {parameters: 3}}]
}
],
invalid: [
{
Expand Down Expand Up @@ -2878,6 +2907,70 @@ ruleTester.run("indent", rule, {
"}",
options: ["tab"],
errors: expectedErrors("tab", [[3, "1 tab", "2 spaces", "ExpressionStatement"], [4, "1 tab", "14 spaces", "ExpressionStatement"]])
},
{
code:
"function foo() {\n" +
" bar();\n" +
"\t\t}",
output:
"function foo() {\n" +
" bar();\n" +
"}",
options: [2],
errors: expectedErrors([[3, "0 spaces", "2 tabs", "BlockStatement"]])
},
{
code:
"function foo() {\n" +
" function bar() {\n" +
" baz();\n" +
" }\n" +
"}",
output:
"function foo() {\n" +
" function bar() {\n" +
" baz();\n" +
" }\n" +
"}",
options: [2, {FunctionDeclaration: {body: 1}}],
errors: expectedErrors([3, 4, 8, "ExpressionStatement"])
},
{
code:
"function foo() {\n" +
" function bar(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" }\n" +
"}",
output:
"function foo() {\n" +
" function bar(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" }\n" +
"}",
options: [2, {FunctionDeclaration: {body: 1, parameters: 2}}],
errors: expectedErrors([3, 6, 4, "Identifier"])
},
{
code:
"function foo() {\n" +
" var bar = function(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" };\n" +
"}",
output:
"function foo() {\n" +
" var bar = function(baz,\n" +
" qux) {\n" +
" foobar();\n" +
" };\n" +
"}",
options: [2, {FunctionExpression: {parameters: 3}}],
errors: expectedErrors([3, 8, 10, "Identifier"])
}
]
});

0 comments on commit 332d213

Please sign in to comment.