3

I'm cleaning up my code with the gjslint tool from Google Closure Tools. It is reporting the following error:

Line 15, E:0222: Member "this._dictionary" must not have @private JsDoc

And this is the code:

/**
 * Stacker class.
 * @constructor
 * @param {frankenstein.app.Dictionary} dictionary input dictionary for stacking.
 */
frankenstein.app.Stacker = function(dictionary) {
  /** @private */ this._dictionary = dictionary;
};

Can somebody explain why this._dictionary must not have @private JsDoc? Thanks!

J. Frankenstein
  • 1,673
  • 14
  • 24
  • I would suspect it's because it is only "private by convention" (e.g. not private-by-closure). –  Jul 25 '12 at 03:42
  • What is the difference? I didn't think that any of the annotations were enforceable. – J. Frankenstein Jul 25 '12 at 03:55
  • But it looks like gslint is trying ;-) Perhaps that "error" can be downgraded to a warning? Or does `@private` alter the Closure Compiler output/heuristics? –  Jul 25 '12 at 04:13

1 Answers1

7

Closure Linter is designed to enforce the Google JavaScript Style Guide. The JSDoc tag @private is documented as follows:

Used in conjunction with a trailing underscore on the method or property name to indicate that the member is private. Trailing underscores may eventually be deprecated as tools are updated to enforce @private.

As of Closure Linter version 2.3.6, the error "Member <name> must not have @private JsDoc" will be emitted whenever a member is annotated @private without a trailing underscore.

This code will not emit any errors or warnings.

/**
 * Stacker class.
 * @constructor
 * @param {frankenstein.app.Dictionary} dictionary Input dictionary for 
 *     stacking.
 */
frankenstein.app.Stacker = function(dictionary) {
  /** @private */ this.dictionary_ = dictionary;
};
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • 1
    Isn't that contradictory?! If you do put the '_' you do not get the warning, but if you do not put it, then it tells you that you should add it even though later it may become deprecated... – Alexis Wilke Apr 07 '14 at 23:44