diff --git a/lib/rules/indent.js b/lib/rules/indent.js index bf238dd18d0..2b069011f99 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -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); } }, @@ -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); } } }; diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js index 007eccbc7b1..cc9e2708fe6 100644 --- a/tests/lib/rules/indent.js +++ b/tests/lib/rules/indent.js @@ -1561,6 +1561,15 @@ 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" + @@ -1568,6 +1577,26 @@ ruleTester.run("indent", rule, { " \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: [ { @@ -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"]) } ] });