why "Optional parameter name %s must be prefixed with opt_." in gjslint --strict mode?

StackOverflow https://stackoverflow.com/questions/15940419

  •  03-04-2022
  •  | 
  •  

Question

I get the following on one particular javascript file

Line 23, E:0233: Optional parameter name category must be prefixed with opt_.
Line 649, E:0233: Optional parameter name animate must be prefixed with opt_.
Line 697, E:0233: Optional parameter name aggregate must be prefixed with opt_.
Line 763, E:0233: Optional parameter name animate must be prefixed with opt_.
Line 796, E:0233: Optional parameter name animate must be prefixed with opt_.

For the first one the code is:

/** @constructor
 *
 *  @param {Object} data an entity or item.
 *  @param {Object} parent a viewObj, or at the root level, a viewstate.
 *  @param {Array.<number>} position an (x$, y$) pair.
 *  @param {string=} category The category to give the item. This forms an
*                             inconsistent mess around where category is stored.
 */
function ViewObj(data, parent, position, category) {

What's the point of the error code? 'category' is not optional!

Was it helpful?

Solution

The = suffix in the type means that it's optional. If the category parameter isn't optional, then you should change its type to string.

The goal of this error is to make sure that it's clear which parameters are optional (and that not only does their type reflect it, but their name as well, in accordance with the style guide gjslint is using), and which are not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top