Browse Source

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>
v7.x
Rich Trott 8 years ago
parent
commit
f785b3662b
  1. 19
      tools/eslint-rules/align-function-arguments.js

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

Loading…
Cancel
Save