Patch that adds JSDoc to backbone-using modules: Quickedit, toolbar, ckeditor, editor.

Added @file to all files.
Wrapped comment lines to 80 char.
Almost all first line comments are actually on one line.
Added JSDoc for all "public" function (but not all descriptions). Some function local function not present in the global scope don't have complete jsdoc yet.

Comments

nod_’s picture

StatusFileSize
new170.79 KB
new19.82 KB
nod_’s picture

StatusFileSize
new39.58 KB
new192.58 KB

Some more 80 char limit and method summary fixes.

nod_’s picture

StatusFileSize
new192.6 KB

Reroll

wim leers’s picture

Holy shit.

wim leers’s picture

Title: JSDoc for backbone using modules » JSDoc for JS using Backbone
Status: Needs review » Needs work
Issue tags: +Documentation

This is such a monumental task, such a big undertaking, that IMHO it'd be fine to commit this patch as-is and then iteratively improve from there. It only touches comments. And it's a big step forward already anyway.

I read the entire thing, and have a few nitpicks, but mostly general questions.

  1. +++ b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js
    @@ -1,9 +1,16 @@
    + * Ckeditor drupalimage admin behavior.
    

    s/Ckeditor/CKEditor/

  2. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -1,9 +1,25 @@
    + * Ckeditor JS API.
    

    s/Ckeditor/CKEditor/

    It's not really a JS API, it's just an implementation of the Drupal.editors API!

  3. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -1,9 +1,25 @@
         attach: function (element, format) {
    
    @@ -26,6 +42,15 @@
         detach: function (element, format, trigger) {
    
    @@ -40,6 +65,13 @@
         onChange: function (element, callback) {
    
    @@ -50,6 +82,15 @@
         attachInlineEditor: function (element, format, mainToolbarId, floatedToolbarId) {
    

    These should all basically be {@inheritdoc}, if that is possible?

  4. +++ b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js
    @@ -1,3 +1,8 @@
    + * Ckeditor sylecombo admin behavior.
    

    s/Ckeditor/CKEditor/
    s/sylecombo/StylesCombo/

  5. +++ b/core/modules/ckeditor/js/plugins/drupallink/plugin.js
    @@ -199,6 +201,7 @@
    +   * @example
    

    No closing tag?

  6. +++ b/core/modules/ckeditor/js/views/KeyboardView.js
    @@ -22,7 +23,7 @@
    -     * {@inheritdoc}
    +     * @inheritdoc
    

    Aha, so it exists? :)

  7. +++ b/core/modules/ckeditor/js/views/VisualView.js
    @@ -32,7 +34,12 @@
    +     * @param {string} [value]
    

    What do the square brackets here mean?

  8. +++ b/core/modules/editor/js/editor.admin.js
    @@ -178,6 +199,14 @@
    +       * @param {Array} propertyValues
    

    Why is it Array with a capital, but a object without?

  9. +++ b/core/modules/editor/js/editor.admin.js
    @@ -664,21 +795,29 @@
    +     * @type {Object.<string, Drupal.FilterStatus>}
    

    Woah, what?

  10. +++ b/core/modules/editor/js/editor.formattedTextEditor.js
    @@ -46,14 +67,19 @@
    +     * @inheritdoc
    +     *
    +     * @return {jQuery}
    ...
    +     * @inheritdoc
    +     *
    +     * @param {object} fieldModel
    +     * @param {string} state
    

    If we have @inheritdoc, then why are these additional things necessary?

  11. +++ b/core/modules/editor/js/editor.js
    @@ -214,6 +218,19 @@
    +   * Attach editor behaviors to the field.
    
    @@ -240,6 +257,17 @@
    +   * Detach editor behaviors from the field.
    

    "Attaches" & "Detaches". We always use 3rd person singular.

jhodgdon’s picture

Wim: thanks for reviewing, which I haven't made time for yet, sorry!

One note: in JSDoc, @inheritdoc means "Inherit the all the parent docs". See #1337022-12: [policy, no patch] Create/adopt JavaScript docs standards compatible with a JS documentation parser for a summary of what inheritdoc means for various docs parsers.... Our usage for PHP is like this too.

Anyway, in JSDoc I do not think you can use @inheritdoc and then add other docs. According to JSDoc docs, it shouldn't work right.

nod_’s picture

Quickly on the inherit doc thing. We have inherit doc all over the place but we inherit from Backbone.Model, or Backbone.View and those things do not have JSDoc documentation. So we're essentially inheriting nothing. Also had to add those because of eslint rasing a warning on those "undocumented" parameters. I'll reply/reroll the rest later.

wim leers’s picture

RE: Backbone + JSDoc: they wontfixed it: https://github.com/jashkenas/backbone/issues/2203 — :(

jhodgdon’s picture

I would not recommend using @inheritdoc unless there is actually doc to inherit. And I still do not think that "@inheritdoc + more" is supported in JSDoc.

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new192.64 KB
new1.79 KB

1,2,4 fixed.

3, there is no parent (it's a namespace), nothing to inherit from. Or you'll have to change the code which I won't do here.

5, no, it's how it's done. example ends when next tag starts or when end of docblock is reached.

6, yep, and it works if the parent exists and is properly documented: http://read.theodoreb.net/drupal-jsapi/Drupal.quickedit.editors.form.html

7, optional parameter.

8, phpstorm doesn't like lowercase Array. I know it's a lame justification but it's just a search/replace fix. Bigger fish and all.

9, that's how you say your object has keys that are strings and values that are Drupal.FilterStatus objects.

10, because of eslint & phpstorm. Eslint show a warning and phpstorm doesn't display types (bug on both of them I know) @jhodgdon: all the extra stuff is ignored by jsdoc, as the doc says. See http://read.theodoreb.net/drupal-jsapi/Drupal.quickedit.editors.form.html it's same docs as http://read.theodoreb.net/drupal-jsapi/Drupal.quickedit.EditorView.html

11, fixed.

jhodgdon’s picture

I looked at the beginning of this patch, which is way too long for a quick review... sorry...

A few questions and ideas:

  1. +++ b/core/modules/ckeditor/js/ckeditor.drupalimage.admin.js
    @@ -1,9 +1,16 @@
    + * CKEditor drupalimage admin behavior.
    

    what's "drupalimage"? If it's a name of a class or variable or something, maybe instead of making this separate words, just use the real name of the class/whatever? As it is, it's not really English or code speak.

  2. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -1,9 +1,25 @@
    + * CKEditor implementation of {@link Drupal.editors} API.
    

    See like this, this is good, because I immediately know that Drupal.editors is a code thing.

  3. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -1,9 +1,25 @@
    +     * @param {HTMLElement} element
    +     * @param {string} format
    +     *
    +     * @return {bool}
    +     */
    

    Need docs on all these.

  4. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -40,6 +65,13 @@
    +    /**
    +     *
    +     * @param {HTMLElement} element
    +     * @param {function} callback
    +     *
    +     * @return {bool}
    +     */
         onChange: function (element, callback) {
    

    No description here for the first line, or for the param/returns?

  5. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -101,6 +142,9 @@
    +    /**
    +     * @param {object} format
    +     */
         _loadExternalPlugins: function (format) {
           var externalPlugins = format.editorSettings.drupalExternalPlugins;
    

    Um. This isn't really docs?

  6. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -117,8 +161,11 @@
    +     * @type {?function}
    

    Is the ? here correct?

nod_’s picture

StatusFileSize
new192.65 KB
new447 bytes

1. name of the ckeditor plugin.

2. agreed.

3. Only this docblock or you'll make me fix all of them one at a time? Because that's the third docblock on the page and there are many more like it below.

4. With documentation like that I'll get picked up by JSDoc and will at least show up in the documentation.

5. Hey at least it's clear a string isn't expected in here.

6. Yes, it's JSDoc way to say a variable can be "null", in this case it happens to be it's default value.

nod_’s picture

StatusFileSize
new194.82 KB
new10.31 KB

@link stuff.

dawehner’s picture

+++ b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js
@@ -46,10 +53,10 @@
-     * @return array

Does it make sense to say at least {Array.

}? Did not managed to look more into that particular patch
eiriksm’s picture

Status: Needs review » Needs work

Woah, OK, so second 200K patch review on one day. I am pretty sure I did not get everything, but here is a couple nitpicks. As the other issue, this is probably ready to go, but these small things, since I saw them, could be fixed first, no?

Also, for the record. As far as I could tell, only comments were added / edited, no code was touched. This is a non-disruptive patch in that way.

OK, so my small points:

  1. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -40,6 +65,13 @@
    +     * @param {function} callback
    

    Ideally we would use @callback here I guess. But this first spree would probably spawn plenty of these

  2. +++ b/core/modules/ckeditor/js/models/Model.js
    @@ -9,26 +9,58 @@
    +       * The configuration for the hidden CKEditor instance that is used to build
    

    81 characters.

  3. +++ b/core/modules/editor/js/editor.admin.js
    @@ -11,69 +11,81 @@
    +     * @fires event:drupalEditorFeatureAdded
    

    I was wondering if you were doing any of these. I guess there will be quite some follow-ups on @listens tags. But OK. Just an observation :)

  4. +++ b/core/modules/editor/js/editor.admin.js
    @@ -11,69 +11,81 @@
    +     * `Drupal.filterSettingsForEditors[filterID].getRules()`.
    

    Did not research this, but if we had an example to put in as a @see comment, that would be nice. This is a nitpick and could also be its own little issue I guess.

  5. +++ b/core/modules/editor/js/editor.admin.js
    @@ -102,22 +114,27 @@
    +       * universe, which shows that it must be allowed to generate the a,
    +       * strong
    +       * and img tags. For the a tag, it must be able to set the "href"
    

    Seems like some reformatting for 80 chars gone wrong :)

  6. +++ b/core/modules/editor/js/editor.admin.js
    @@ -593,59 +711,72 @@
    +   * @example <caption>Whitelist the "p", "strong" and "a" HTML tags.</caption>
    

    @example on its own line, caption tag on the following?

  7. +++ b/core/modules/editor/js/editor.admin.js
    @@ -593,59 +711,72 @@
    +   * @example <caption>For the "a" HTML tag, only allow the "href" attribute
    

    Same as above

  8. +++ b/core/modules/editor/js/editor.admin.js
    @@ -593,59 +711,72 @@
    +   * @example <caption>For all tags, allow the "data-*" attribute (that is, any
    

    ...and again

  9. +++ b/core/modules/editor/js/editor.js
    @@ -214,6 +218,19 @@
    +   * @listens event:change
    

    Awesome, there is one of those (mentioned above). There is probably a lot more of those not in your patches (I think I spotted a couple), but that's for other issues.

  10. +++ b/core/modules/quickedit/js/models/FieldModel.js
    @@ -178,13 +246,14 @@
    -      // The user is in-place editing this entity, and this field is a candidate
    +      // The user is in-place editing this entity, and this field is a
    +      // candidate
           // for in-place editing. In-place editor should not
    

    I don't get why you changed this. Seems this line used to be 80 chars, but you pushed one word onto a new line, making that the only word on that line?

  11. +++ b/core/modules/quickedit/js/models/FieldModel.js
    @@ -224,11 +292,12 @@
    +      //   deed is done. Then: 1) transition to 'inactive' to allow the field
    +      // to
    +      //   be rerendered, 2) destroy the FieldModel (which also destroys
    

    another instance of "one word on one line"

  12. +++ b/core/modules/quickedit/js/quickedit.js
    @@ -82,23 +86,25 @@
    +      // immediately. New fields will be unable to be processed immediately,
    +      // but
    +      // will instead be queued to have their metadata fetched, which occurs
    

    ...and here

  13. +++ b/core/modules/quickedit/js/theme.js
    @@ -10,10 +10,11 @@
    +   *   the id to apply to the backstage.
    

    Super extreme nitpick here, but this should probably use sentence case.

  14. +++ b/core/modules/quickedit/js/views/EditorView.js
    @@ -7,36 +7,35 @@
    +     * Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
    

    New line after @example?

Again, this is awesome work @nod_!

ashutoshsngh’s picture

Assigned: Unassigned » ashutoshsngh
ashutoshsngh’s picture

Assigned: ashutoshsngh » Unassigned
shamsher_alam’s picture

Assigned: Unassigned » shamsher_alam
shamsher_alam’s picture

Status: Needs work » Needs review
StatusFileSize
new205.27 KB
nod_’s picture

Assigned: shamsher_alam » nod_
StatusFileSize
new195.12 KB
new7.62 KB

Sorry your patch had PHP in it. This is a JS-only patch. Also with a patch this size an interdiff is required, otherwise it's impossible to know what's going on.

(edit) The interdiff is between #13 and this patch.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

All the feedback from @eiriksm got adressed

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patches/reviews!

Follow-ups that I noticed, besides the generic "fill this in better":

core/modules/editor/js/editor.admin.js:
- Needs attention for line wrapping/formatting
- Lots of doc blocks have paragraphs of description but lack a one-line summary at the start
- Does JSDoc support numbered lists? I know that the API module doesn't, so comments like:

+   *  1. use the "tags" key to list HTML tags, and set the "allow" key to
+   *     either true (to allow these HTML tags) or false (to forbid these HTML
+   *     tags). If you leave the "tags" key's default value (the empty array),
+   *     no restrictions are applied.
+   *  2. all nested within the "restrictedTags" key: use the "tags" subkey to
+   *     list HTML tags to which you want to apply property restrictions, then
+   *     use the "allowed" subkey to whitelist specific property values, and
+   *     similarly use the "forbidden" subkey to blacklist specific property
+   *     values.

will not format correctly. Should check the JSDoc output and see if this works. Probably this one would actually be better as a bullet list anyway, because it's not really ordered information. (This is in the docs for Drupal.FilterHTMLRule by the way).

core/modules/editor/js/editor.js
- There seem to be a number of doc blocks without the @constructor, @type, or other indication of what exactly they are. Possibly I'm wrong about this, but I thought you had to put something in the doc block to tell JSDoc what is being documented, or it wouldn't pick it up?
- I noticed @prop there, which I guess is a legal synonym of @property for JSDoc. But I think elsewhere in the JS codebase we're using @property. It would be nice to pick one and standardize I think within Drupal, as much as possible?

Generically:

I find it really confusing to see something like this:

+     * @param {string} from
+     * @param {string} to
+     * @param {object} context
+     * @param {string} context.reason
+     * @param {bool} context.confirming
+     *
+     * @return {bool}
+     *
+     * @see Drupal.quickedit.AppView#acceptEditorStateChange
+     */
     _acceptStateChange: function (from, to, context) {

The function parameters are from, to, and context. The lines like @param context.reason are telling us about properties of the context object. Is this really the standard way to do that? It seems very very very odd to me.

In PHP land, we'd do something like this:

* @param object $context
*    An object with the following properties:
*    - reason: The reason for ...

Anyway... Committed as-is to 8.0.x. Thanks everyone for the patches and reviews!

  • jhodgdon committed 38833e0 on 8.0.x
    Issue #2493683 by nod_, dawehner, eiriksm, Wim Leers: JSDoc for JS using...
eiriksm’s picture

StatusFileSize
new22.25 KB

Wohoo!

The function parameters are from, to, and context. The lines like @param context.reason are telling us about properties of the context object. Is this really the standard way to do that? It seems very very very odd to me.

In PHP land, we'd do something like this:

It is the standard, yes. Also, personally I find it better, expecially the output when you are documenting like that. The above example outputs this, for example:

jsdoc output

This tells me (in the same way it describes the parameters) that the object consists of those properties, with those types.

Granted, it is not ideal that this is not the same as the php way, and also, I guess this is somewhat a matter of taste as well.

Anyway, great work to everyone involved, and especially @nod_! :)

jhodgdon’s picture

Good enough! We should not try to shoehorn JS into PHP standards necessarily, and as long as JSDoc is happy that is good enough. Thanks for the explanation.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.