How to show error on number of parameters mismatch Webstorm NodeJs ?

Number of params mismatch but Webstorm is not giving any error, how can I add this inspection? 

 

Also in my fucntion, I am adding a parameter which I am not using, and I have also enabled unresolved variable inspection, but no error is showing?

 

Please help me.

28 comments

>Number of params mismatch but Webstorm is not giving any error, how can I add this inspection? 

Please make sure to enable Signature mismatch inspection (Settings | Editor | Inspections | JavaScript | General)

 

>Also in my fucntion, I am adding a parameter which I am not using, and I have also enabled unresolved variable inspection, but no error is showing?

 

Make sure that Unused local symbol inspection (Settings | Editor | Inspections | JavaScript | General) is enabled, and Ignore unused parameters is set to None

0

I have added 'Signature mismatch' and `Unused local symbol` but I didn't find `Ignore unused parameters` under javascript?

 

Also, none of the problem mentioned above is getting resolved. I am still able to add an unused param in a function and still, I am calling my function with the number of params not equal to function parameters. And no error is being shown.

 

Please Help.

Thanks

0

>I didn't find `Ignore unused parameters` under javascript?

It's an option of Unused local symbol inspection:

 

>I am still able to add an unused param in a function and still, I am calling my function with the number of params not equal to function parameters. And no error is being shown.

 

Please provide code snippets that show up the issues

0
function fun(param1, callback) {
callback();
}

As you can see above I am not using param1 but I am not getting error shown

function fun(param1, callback) {
let a;
callback();
}

As in the above code, I am not using variable `a`, so an error should be shown.

function fun(param1, callback) {
let a;
callback();
}

fun(param1);

While calling above function an error must be shown as it is a signature mismatch?

Please help me.
Thanks
0

Works for me:

as you can see, param1 and a are marked unused (grey color), and Signature mismatch errors are reported for function call.

You need to make sure to change `Ignore unused parameters` for `Unused local symbol` to None


and enable `Guess optionality of parameters` for `Signature mismatch` inspection:

1

Now Signature Mismatch is working because previously I wasn't setting `Guess optionality of parameters`, now it is working fine.

 

Also for `Unused local symbol` I want my variable to show error with red colour, not grey colour warning?

 

Thanks

0

Also, one more thing Signature Mismatch is coming only when number of params when calling the function is more than the accepted params of the function but I want this error to be shown whenever there is mismatch for e.g

function fun(param1, callback) {
let a;
callback();
}

fun(callback); // Here error is not shown, but should be shown as number of params are mismatched

fun('abc', 'hello', callback); // Here error is shown
0

>Also for `Unused local symbol` I want my variable to show error with red colour, not grey colour warning?

Try changing Errors and Warnings | Unused symbol foreground color acordingly in Settings | Editor | Color Scheme | General

 


1

Thanks  a lot it's working, can you tell me how can I show signature mismatch asked just above your post https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000183339/comments/360000050200 

0

as you can see in my comment above, inspection does work for me if I'm passing a single parameter:

0

But in my case function is not getting red colour when the number of params is lesser?

 Also, want my function to get red colour like above if then function does not returns something but I am expecting a return type for e.g

function fun(str) {

      //return str.size();

}

let s = fun("string"); // there should be error as this function isn't returning anything

 Also is there any way other than separately adding all of these errors like any library or something

 

Thanks a lot for helping.

 

0

Also, want my function to get red colour like above if then function does not returns something but I am expecting a return type for

How can the IDE know that you are expecting this function to return smth? Because you are assigning it to a var? there is no such inspection, please feel free to file a request for it to youtrack, https://youtrack.jetbrains.com/issues/WEB

0

How can the IDE know that you are expecting this function to return smth? Because you are assigning it to a var? there is no such inspection, please feel free to file a request for it to youtrack, https://youtrack.jetbrains.com/issues/WEB



function
fun(str) {

      return str.size();

}

let s = fun("string");

Now here as compiler knows that the function `fun` is returning something, So IDE already knows to show error here or not.

 

0

Do't understand what you meant to say, sorry. Here your function does have a return statement, so what errors do you expect to see?

0

I am saying IDE knows that I am returning soemthign from a function or not, then why does IDE don't show the error for below case

 

function fun(param){

}

let mssg = fun("hello");// Here as IDE knows that fun does not return anything IDE should show error.

 

0

In other IDE's like Android Studio it shows error, but here not, why?

0

Android Studo provides no support for JavaScript

0

I mean in java it shows the error then why can't in Webstorm(Javascript) ?

0

Because Java is not Javascript:) Java is a strong statically typed language; and assigning a void function to variable causes compiler error here because of type mismatch. Javascript is a dynamic wealky typed language. It does't have 'void' type - in Javascript, a function is implicitly returning 'undefined' if no return statement is provided.

1

Ok, the last thing when I am passing fewer params in a function call then why the error is not getting shown? only working if I am passing more params?

0

no idea - as i wrote, it works fine for me. Try invalidating caches (File | Invalidate caches, Invalidate and restart) - does the issue persist? if yes, please provide a project that can be used to recreate it

0

Did Invalidate cache and restart but again it is not working, Actually the thing is in error it shows "Invalid number of arguments, expected 0..2" So I think because of which it is allowing params to be less than or equal to the expected params but not greater?


0

Actually there is something strange happening, for below two codes

function fun(prod_number) {
let message = new gcm.Message({
priority: 'high'
});
message.addData('prod_number', prod_number);
}

fun();//Not showing any error

But for below code it is showing error

function fun(prod_number) {

}

fun();//Now it is showing error

Why is this happening?

0

This issue is still not resolved?

0

It's current status is 'submitted'; you will be notified on any progress with https://youtrack.jetbrains.com/issue/WEB-33842

1

Still, there is no response from their side :(

0

Please sign in to leave a comment.