JSDoc to suppress a single "Unused local variable"

I have a variable that I declare as an enum so that I can use it to documentation variables and parameters that take on a restricted set of values.  Something like this:

    /**
     * Possible values for the position of a widget.
     * This object exists solely for documentation.
     * @enum {string}
     */
    var POSITION = {
        "left": "left",
        "right": "right",
        "center": "center"
    };


    /**
     * Return the position that is the mirror opposite of specified position
     * @param {POSITION} pos
     */
    function mirrorPosition(pos) {
        return pos === 'left' ? 'right' :
            pos === 'right' ? 'left' :
                pos;    // center
    }

Webstorm flags the variable POSITION as unused.  Is there a way to suppress the inspection for just this variable?  If not, should WebStorm be smart enough to consider usages in JSDoc to be usages?

3 comments

WebStorm 10.0.4 seems to correctly resolve POSITION usages - no warnings are reported:

enum.png

Anyway, you can suppress such warcings by adding

//noinspection JSUnusedLocalSymbols

above declaration, like:

//noinspection JSUnusedLocalSymbols
  /**
* Possible values for the position of a widget.
* This object exists solely for documentation.
* @enum {string}
*/
var POSITION = {
0

You're correct that my standalone example generates no warning. However, I'm using the require.js framework, and this slightly more complicated example still has the warning:

 
define(
    [],
    function() {
        /**
         * Possible values for the position of a widget.
         * This object exists solely for documentation.
         * @enum {string}
         */
        var POSITION
= {
            "left": "left",
            "right": "right",
            "center": "center"
        
};

        /**
         * Return the position that is the mirror opposite of specified position
         * @param {POSITION} pos
         */
        function mirrorPosition
(pos) {
            return pos === 'left' ? 'right' :
                pos === 'right' ? 'left' :
                    pos;    // center
        
}

        return mirrorPosition;
    });


Fortunately, the noinspection comment works.  

Should I file a bug report?

0
Should I file a bug report?

Yes, please!

0

Please sign in to leave a comment.