user736893
user736893

Reputation:

Disable warning for "unused property" only for specific functions/variables?

Original Question:

I have some JavaScript functions that are only referenced from outside of my project. Is there any way to tell WebStorm not to warn on those but still warn on others? Perhaps with JSDoc or similar syntax?

Example:

function externallyCalled() {
    //this should not show a warning if not used
}

function internalFunction() {
   //this should show a warning if it's not used
}

Is this possible?


edit:

Based on Vipin's answer, // noinspection JSUnusedGlobalSymbols works outside of a closure but not inside:

enter image description here

I have opened https://youtrack.jetbrains.com/issue/WI-39066 and accepted @Vipin's answer.

Upvotes: 0

Views: 2143

Answers (1)

Vipin Kumar
Vipin Kumar

Reputation: 6546

You can add // noinspection JSUnusedGlobalSymbols where you want to suppress the warning like below

// noinspection JSUnusedGlobalSymbols
function externallyCalled() {
    //this should not show a warning if not used
}

// noinspection JSUnusedGlobalSymbols
function internalFunction() {
    //this should show a warning if it's not used
}

Quick Fix Menu enter image description here

Edited:

For closure, one way is to add // noinspection JSUnusedGlobalSymbols on top of return like below

var app = (function () {
    // noinspection JSUnusedGlobalSymbols
    return {
        externallyCalled: function () {
            //this should not show a warning if not used
        },
        internalFunction: function () {
            //this should show a warning if it's not used
        }
    }
})();

This will disable the warnings on all the public properties/methods of returned object.

Upvotes: 3

Related Questions