Skip to content

Commit 0ad4d33

Browse files
not-an-aardvarkkaicataldo
authored andcommitted
Fix: indent regression with function calls (fixes #7732, fixes #7733) (#7734)
1 parent ab246dd commit 0ad4d33

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/rules/indent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,12 @@ module.exports = {
737737
} else if (parent.type === "CallExpression" || parent.type === "NewExpression") {
738738
if (typeof options.CallExpression.arguments === "number") {
739739
nodeIndent += options.CallExpression.arguments * indentSize;
740-
} else if (parent.arguments.indexOf(node) !== -1) {
741-
nodeIndent = parent.arguments[0].loc.start.column;
740+
} else if (options.CallExpression.arguments === "first") {
741+
if (parent.arguments.indexOf(node) !== -1) {
742+
nodeIndent = parent.arguments[0].loc.start.column;
743+
}
744+
} else {
745+
nodeIndent += indentSize;
742746
}
743747
} else if (parent.type === "LogicalExpression" || parent.type === "ArrowFunctionExpression") {
744748
nodeIndent += indentSize;

tests/lib/rules/indent.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,50 @@ ruleTester.run("indent", rule, {
18631863
" [\n" +
18641864
" ]()",
18651865
options: [4, {CallExpression: {arguments: "first"}, ArrayExpression: "first"}]
1866+
},
1867+
1868+
// https://github.com/eslint/eslint/issues/7732
1869+
{
1870+
code:
1871+
"const lambda = foo => {\n" +
1872+
" Object.assign({},\n" +
1873+
" filterName,\n" +
1874+
" {\n" +
1875+
" display\n" +
1876+
" }\n" +
1877+
" );" +
1878+
"}",
1879+
options: [2, {ObjectExpression: 1}],
1880+
parserOptions: { ecmaVersion: 6 }
1881+
},
1882+
{
1883+
code:
1884+
"const lambda = foo => {\n" +
1885+
" Object.assign({},\n" +
1886+
" filterName,\n" +
1887+
" {\n" +
1888+
" display\n" +
1889+
" }\n" +
1890+
" );" +
1891+
"}",
1892+
options: [2, {ObjectExpression: "first"}],
1893+
parserOptions: { ecmaVersion: 6 }
1894+
},
1895+
1896+
// https://github.com/eslint/eslint/issues/7733
1897+
{
1898+
code:
1899+
"var foo = function() {\n" +
1900+
"\twindow.foo('foo',\n" +
1901+
"\t\t{\n" +
1902+
"\t\t\tfoo: 'bar'," +
1903+
"\t\t\tbar: {\n" +
1904+
"\t\t\t\tfoo: 'bar'\n" +
1905+
"\t\t\t}\n" +
1906+
"\t\t}\n" +
1907+
"\t);\n" +
1908+
"}",
1909+
options: ["tab"]
18661910
}
18671911
],
18681912
invalid: [

0 commit comments

Comments
 (0)