From f785b3662b79e8419b2e7d57b4b50102de2b1d44 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 17 Sep 2016 20:24:47 -0700 Subject: [PATCH] tools: make argument alignment linting more strict A few nits in recent PR comments suggest that we can have slightly more strict linting for argument alignment in multiline function calls. This enables the existing linting requirements to apply when one or more of the arguments themselves are function calls. Previously, that situation had been excluded from linting. Refs: https://github.com/nodejs/node/pull/8628#issuecomment-247797311 PR-URL: https://github.com/nodejs/node/pull/8642 Reviewed-By: Teddy Katz Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Ilkka Myller Reviewed-By: Franziska Hinkelmann --- .../eslint-rules/align-function-arguments.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/eslint-rules/align-function-arguments.js b/tools/eslint-rules/align-function-arguments.js index 55ce5a4fdbb7c9..015552489a9d44 100644 --- a/tools/eslint-rules/align-function-arguments.js +++ b/tools/eslint-rules/align-function-arguments.js @@ -30,7 +30,6 @@ function checkArgumentAlignment(context, node) { const ignoreTypes = [ 'ArrowFunctionExpression', - 'CallExpression', 'FunctionExpression', 'ObjectExpression', ]; @@ -48,18 +47,26 @@ function checkArgumentAlignment(context, node) { return; } + var misaligned; + args.slice(1).forEach((argument) => { - if (argument.loc.start.line === currentLine + 1) { - if (argument.loc.start.column !== firstColumn) { - msg = 'Function called with argument in column ' + - `${argument.loc.start.column}, expected in ${firstColumn}`; + if (!misaligned) { + if (argument.loc.start.line === currentLine + 1) { + if (argument.loc.start.column !== firstColumn) { + if (isNodeFirstInLine(argument)) { + msg = 'Function argument in column ' + + `${argument.loc.start.column + 1}, ` + + `expected in ${firstColumn + 1}`; + misaligned = argument; + } + } } } currentLine = argument.loc.start.line; }); if (msg) - context.report(node, msg); + context.report(misaligned, msg); } module.exports = function(context) {