diff --git a/lib/rules/function-paren-newline.js b/lib/rules/function-paren-newline.js index 898e113ee8e..a5b8f0d70c6 100644 --- a/lib/rules/function-paren-newline.js +++ b/lib/rules/function-paren-newline.js @@ -191,10 +191,13 @@ module.exports = { function getParenTokens(node) { switch (node.type) { case "NewExpression": - if (!node.arguments.length && !( - astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) && - astUtils.isClosingParenToken(sourceCode.getLastToken(node)) - )) { + if (!node.arguments.length && + !( + astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) && + astUtils.isClosingParenToken(sourceCode.getLastToken(node)) && + node.callee.range[1] < node.range[1] + ) + ) { // If the NewExpression does not have parens (e.g. `new Foo`), return null. return null; diff --git a/tests/lib/rules/function-paren-newline.js b/tests/lib/rules/function-paren-newline.js index 048370f356a..a8c7cc85827 100644 --- a/tests/lib/rules/function-paren-newline.js +++ b/tests/lib/rules/function-paren-newline.js @@ -30,6 +30,7 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); ruleTester.run("function-paren-newline", rule, { valid: [ + "new new Foo();", // multiline option (default) "function baz(foo, bar) {}", @@ -1174,6 +1175,18 @@ ruleTester.run("function-paren-newline", rule, { options: ["never"], errors: [LEFT_UNEXPECTED_ERROR] }, + { + code: ` + new new C()( + ); + `, + output: ` + new new C()(); + `, + options: ["never"], + errors: [LEFT_UNEXPECTED_ERROR, RIGHT_UNEXPECTED_ERROR] + }, + { code: ` function baz(