Skip to content
Permalink
Browse files

Fix: ignore argument parens in no-unexpected-multiline (fixes #4658)

  • Loading branch information...
alberto committed Dec 23, 2015
1 parent 505c403 commit acdda24120dddfbf98fbc304b8691e27e6743589
Showing with 12 additions and 11 deletions.
  1. +10 −10 lib/rules/no-unexpected-multiline.js
  2. +2 −1 tests/lib/rules/no-unexpected-multiline.js
@@ -14,18 +14,20 @@ module.exports = function(context) {
var PROPERTY_MESSAGE = "Unexpected newline between object and [ of property access.";

/**
* Check to see if the bracket prior to the node is continuing the previous
* Check to see if there is a newline between the node and the following open bracket
* line's expression
* @param {ASTNode} node The node to check.
* @param {string} msg The error message to use.
* @returns {void}
* @private
*/
function checkForBreakBefore(node, msg) {
var tokens = context.getTokensBefore(node, 2);
var paren = tokens[1];
var before = tokens[0];
if (paren.loc.start.line !== before.loc.end.line) {
function checkForBreakAfter(node, msg) {
var paren = context.getTokenAfter(node);
while (paren.value === ")") {
paren = context.getTokenAfter(paren);
}

if (paren.loc.start.line !== node.loc.end.line) {
context.report(node, paren.loc.start, msg, { char: paren.value });
}
}
@@ -40,16 +42,14 @@ module.exports = function(context) {
if (!node.computed) {
return;
}

checkForBreakBefore(node.property, PROPERTY_MESSAGE);
checkForBreakAfter(node.object, PROPERTY_MESSAGE);
},

"CallExpression": function(node) {
if (node.arguments.length === 0) {
return;
}

checkForBreakBefore(node.arguments[0], FUNCTION_MESSAGE);
checkForBreakAfter(node.callee, FUNCTION_MESSAGE);
}
};

@@ -23,7 +23,8 @@ ruleTester.run("no-unexpected-multiline", rule, {
"var a = b;\n[1, 2, 3].forEach(console.log)",
"var a = b\nvoid [1, 2, 3].forEach(console.log)",
"\"abc\\\n(123)\"",
"var a = (\n(123)\n)"
"var a = (\n(123)\n)",
"f(\n(x)\n)"
],
invalid: [
{

0 comments on commit acdda24

Please sign in to comment.
You can’t perform that action at this time.