Skip to content

Commit f785b36

Browse files
committed
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: #8628 (comment) PR-URL: #8642 Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ilkka Myller <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 4316f4d commit f785b36

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tools/eslint-rules/align-function-arguments.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function checkArgumentAlignment(context, node) {
3030

3131
const ignoreTypes = [
3232
'ArrowFunctionExpression',
33-
'CallExpression',
3433
'FunctionExpression',
3534
'ObjectExpression',
3635
];
@@ -48,18 +47,26 @@ function checkArgumentAlignment(context, node) {
4847
return;
4948
}
5049

50+
var misaligned;
51+
5152
args.slice(1).forEach((argument) => {
52-
if (argument.loc.start.line === currentLine + 1) {
53-
if (argument.loc.start.column !== firstColumn) {
54-
msg = 'Function called with argument in column ' +
55-
`${argument.loc.start.column}, expected in ${firstColumn}`;
53+
if (!misaligned) {
54+
if (argument.loc.start.line === currentLine + 1) {
55+
if (argument.loc.start.column !== firstColumn) {
56+
if (isNodeFirstInLine(argument)) {
57+
msg = 'Function argument in column ' +
58+
`${argument.loc.start.column + 1}, ` +
59+
`expected in ${firstColumn + 1}`;
60+
misaligned = argument;
61+
}
62+
}
5663
}
5764
}
5865
currentLine = argument.loc.start.line;
5966
});
6067

6168
if (msg)
62-
context.report(node, msg);
69+
context.report(misaligned, msg);
6370
}
6471

6572
module.exports = function(context) {

0 commit comments

Comments
 (0)