dox icon indicating copy to clipboard operation
dox copied to clipboard

Override detected code with jsdoc directives?

Open trusktr opened this issue 9 years ago • 3 comments

It's been a while, but I'll be coming back to dox!

Question: does dox look at the comments when it can't infer from the code? Can we make it prioritize the comments over the code?

For example, I have

/**
 * This is the HTML entry point. This is what fires the app running.
 *
 * @class app
 *
 * @example
 * <app />
 */
angular.module('app').directive('app', function() {
  return {
    template: require('./app.html'),
    restrict: 'E', // custom element only, not attribute directive.
    scope: {}, // use isolate scope for custom elements.
    transclude: false, // if true, means the custom element can have children. Place the children anywhere inside the template using ng-transclude.
    controller: AppCtrl,
    controllerAs: 'app',
    bindToController: true, // always bind to controller with isolate-scope element directives.
  };
});

Since Angular directives aren't a standard JS thing, I thought I'd just use the @class jsdoc directive to document it (in Angular 2 they are classes anyways). I'm using dox 0.8.1 in dox-foundation, but the class docs don't show up. For example, here's what an actual ES6 class doc looks like in dox-foundation:

screen shot 2016-05-15 at 7 16 44 pm

But, here's what happens with the above sample code:

screen shot 2016-05-15 at 7 17 22 pm

which leads me to believe that the JSON that dox returns to dox-foundation is different in that case, which is why dox-foundation renders it differently. Is there (maybe we can add) an option to prioritize comments over code?

trusktr avatar May 16 '16 02:05 trusktr

If a tag is defined in the comment which matches something we infer, it absolutely should override the inferred meaning. So if that's not happening then something's wrong.

I would have to see the actual json being produced to chase down that issue, tho.

Twipped avatar May 16 '16 16:05 Twipped

Well, in my case, the tag doesn't match the inferred thing, so it's ignored. So, what I mean is (what I would like), if I say something is a @class in the jsdoc-style comment, then dox should just trust my comment, and ignore the code (not make inference).

As with the above example, dox seems to ignore it because (as you said) the @class doesn't match with what's inferred.

I think it's a good case to prioritize comments over code because in reality there's no way we can infer all code cases (as in my example, but there are many more).

(I'm also not sure @class is the best choice for my example, but I'm not sure what else to pick, if any).

trusktr avatar May 16 '16 18:05 trusktr

I guess what I'd want in my case is to write @directive, but have that behave like @class, so that (based on the above screenshot) the blue "class" label would instead contain "directive", and perhaps then my template can place <myDirective /> instead of new myDirective() next to the label.

trusktr avatar May 16 '16 18:05 trusktr