Skip to content

Commit

Permalink
fix: function-paren-newline: false negative case support
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 9, 2022
1 parent d42e865 commit dc0854e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/rules/function-paren-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ module.exports = {
function getParenTokens(node) {
switch (node.type) {
case "NewExpression":
if (node.callee.type === "NewExpression" ||
!node.arguments.length && !(
if (!node.arguments.length &&
!(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
astUtils.isClosingParenToken(sourceCode.getLastToken(node))
)) {
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;
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/function-paren-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,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(
Expand Down

0 comments on commit dc0854e

Please sign in to comment.