Skip to content

Commit

Permalink
tools: make argument alignment linting more strict
Browse files Browse the repository at this point in the history
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: nodejs#8628 (comment)
PR-URL: nodejs#8642
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information
Trott committed Sep 20, 2016
1 parent 4316f4d commit f785b36
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tools/eslint-rules/align-function-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function checkArgumentAlignment(context, node) {

const ignoreTypes = [
'ArrowFunctionExpression',
'CallExpression',
'FunctionExpression',
'ObjectExpression',
];
Expand All @@ -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) {
Expand Down

0 comments on commit f785b36

Please sign in to comment.