You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
Highlighting of function invocations with too many arguments can be counter-intuitive if the function call stretches over multiple lines.
Minimal Example:
function functionName(a, b){}
// ^^^^^^^^^^^^^^^^^^ Secondary location is the function declaration.
functionName(
arg1,
arg2,
arg3,
arg4
);
// ^ Primary issue location at the end of the call expression
// (the closing parenthesis is the last token of the call expression).
A real-world example is described and discussed here.
The proposed solution is to change the primary location and introduce more secondary locations, as follows:
Primary location should be moved to the callee, so that the main error message appears before the opening parenthesis.
Every superfluous argument should be reported with a secondary location.
If the callee is a single identifier, then this identifier should be used in the error message: "The function {identifier} expects {N} arguments, but {M} were provided."; That is, if the call looks like f(x), then f should be the primary location.
If the callee is a member expression, then the method name should be used in the same message template. That is, if the call looks like expr.methodName(a1, ..., aN), then expr.methodName should be the primary location, and methodName should be used in the message.
In all other cases (where no good name can be found), the original message "This function expects {N} arguments, but {M} were provided." should be preserved.
For the example above, it would mean:
function functionName(a, b){}
// ^^^^^^^^^^^^^^^^^^ Secondary location at the function declaration.
functionName(
// ^^^^^^^^^^^^ primary location at the callee
arg1,
arg2,
arg3,
// ^^^^ secondary location at superfluous argument
arg4
// ^^^^ secondary location at superfluous argument
);
The text was updated successfully, but these errors were encountered:
andrey-tyukin-sonarsource
changed the title
Rule S930: highlighting of secondary locations should be improved for no-extra-arguments
Rule S930: improve highlighting for no-extra-arguments
Sep 4, 2020
Highlighting of function invocations with too many arguments can be counter-intuitive if the function call stretches over multiple lines.
Minimal Example:
A real-world example is described and discussed here.
The proposed solution is to change the primary location and introduce more secondary locations, as follows:
f(x)
, thenf
should be the primary location.expr.methodName(a1, ..., aN)
, thenexpr.methodName
should be the primary location, andmethodName
should be used in the message.For the example above, it would mean:
The text was updated successfully, but these errors were encountered: