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 <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>
pull/8642/head
Rich Trott 2016-09-17 20:24:47 -07:00
parent 4316f4df31
commit f785b3662b
1 changed files with 13 additions and 6 deletions

View File

@ -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) {