stitch icon indicating copy to clipboard operation
stitch copied to clipboard

Add warnings to provide documentation

Open mathew-odwyer opened this issue 1 year ago • 6 comments
trafficstars

My projects has some fairly strict rules around documentation. It would be neat to have some warnings around missing documentation for variables, functions, enums, etc.

mathew-odwyer avatar Feb 07 '24 02:02 mathew-odwyer

Can you provide some examples of the kinds of cases you'd want to see error info for, and what info you'd want to see in the error messages?

adam-coster avatar Feb 07 '24 18:02 adam-coster

We should implement support for the following warnings:

  • A warning should be triggered when a description is missing for a variable, function, enumeration, etc.
  • If a param/argument tag is missing for a function with parameters, a warning should be displayed.
    • Additionally, if the parameter type is not specified, a warning could be shown.
  • A warning should be raised when no return type is specified for a function.
  • Warnings should be generated where a type is not specified for variables, return types, etc.

Something as simple as:

Missing JSDoc description tag for {name here} Missing JSDoc argument tag for type {function name - parameter name} Missing JSDoc return tag for {function name here}

Furthermore, perhaps providing support for access modifiers or simply supporting /// @ignore would be a great addition, too :).

mathew-odwyer avatar Feb 09 '24 09:02 mathew-odwyer

I like these, though since we don't have a strong desire for them ourselves they unfortunately won't be very high up on my priority queue.


For future reference for myself, or for anyone who wants to take a crack at this.

When functions are processed we already know if they have docs:

https://github.com/bscotch/stitch/blob/87783b9ababee4095308a131d41e1e850029d61f/packages/parser/src/visitor.functionExpression.ts#L19

Logic could be added to look at the JSDoc contents, and add diagnostic errors via this.PROCESSOR.addDiagnostic().

Since not all users would want this, we'd need to add some Diagnostic containers specifically for this purpose to allow filtering:

https://github.com/bscotch/stitch/blob/87783b9ababee4095308a131d41e1e850029d61f/packages/parser/src/project.diagnostics.ts#L7

Those new collections would probably be something like:

  • JSDOC_MISSING_DESCRIPTION
  • JSDOC_MISSING_RETURN
  • JSDOC_MISSING_PARAM
  • JSDOC_MISSING_PARAM_TYPE

After all of that we'll be getting the new diagnostics. BUT, since most users won't want that extra diagnostic info we'd need to also update the extension to allow configuration of which diagnostics the user wants. Currently we DON'T have a config option for that, but that's definitely something we'll want at some point anyway. I'm not sure what the best way would be to handle that, but poking around at other extensions they seem to use fully separate config options for each entry (or otherwise use a separate config file from the VSCode config, a la eslint.

Having them in the Extension config would probably be best, though. The config entries could be something like "stitch.diagnostics.enable.JSDOC_MISSING_DESCRIPTION" booleans or something.

adam-coster avatar Feb 19 '24 23:02 adam-coster

Is this something I could look at implementing?

mathew-odwyer avatar Mar 06 '24 08:03 mathew-odwyer

Is this something I could look at implementing?

Definitely! It's complicated, especially if you aren't used to the Node.js ecosystem, so it'll take some doing. You can make a draft PR to ask questions as you go.

I haven't added much documentation for development setup, but that's something I can do sometimes this week to reduce initial friction

adam-coster avatar Mar 06 '24 15:03 adam-coster

That sounds great, I'd love to see this feature through to the end.

mathew-odwyer avatar Mar 07 '24 07:03 mathew-odwyer