Problem/Motivation

The @param and @return documentation in displace.js committed in #1847084: Measure/track displacing elements better + provide change events for them (fix overlay + toolbar) does not follow the Doxygen format documented at http://drupal.org/node/1354.

http://drupal.org/node/1354#param
http://drupal.org/node/1354#return

JavaScript coding standards: http://drupal.org/node/172169

Brought up in #77 and discussed in a few comments afterwards:
#1847084-77: Measure/track displacing elements better + provide change events for them (fix overlay + toolbar)

Committed code:

+++ b/core/misc/displace.jsundefined
@@ -0,0 +1,179 @@
+   * @param {jQuery} $el
+   *   The jQuery element whose dimensions and placement will be measured.
+   *
+   * @param {string} edge
+   *   The name of the edge of the viewport that the element is associated
+   *   with.

Proposed change:

+++ b/core/misc/displace.jsundefined
@@ -0,0 +1,179 @@
+   * @param jQuery $el
+   *   The jQuery element whose dimensions and placement will be measured.
+   * @param string edge
+   *   The name of the edge of the viewport that the element is associated
+   *   with.

Proposed resolution

Remove curly braces from data types in docblocks, remove extra lines between each @param.

Remaining tasks

A patch needs to be created that makes these changes.

User interface changes

n/a

API changes

n/a

#1847084: Measure/track displacing elements better + provide change events for them (fix overlay + toolbar)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

star-szr’s picture

+++ b/core/misc/displace.jsundefined
@@ -0,0 +1,179 @@
+   * @param {jQuery} $el
+   *   The jQuery element whose dimensions and placement will be measured.
+   *
+   * @param {string} edge
+   *   The name of the edge of the viewport that the element is associated
+   *   with.

Another thing I'm curious about - is there a reason why $el has a dollar sign but edge doesn't?

star-szr’s picture

Issue summary: View changes

Add more 1354 citations

star-szr’s picture

Issue summary: View changes

Remove unneeded word: "standard"

jessebeach’s picture

The '$' character in a variable name is a convention used to distinguish a jQuery set of DOM elements for a DOM element. It's a hint that jQuery methods an be used with this variable.

star-szr’s picture

Makes sense, thanks! Is this documented anywhere?

nod_’s picture

I think so, in case it's not it should be added in this issue: #1778828-7: [policy, no patch] Update JS coding standards

Wim Leers’s picture

Should we also remove the curly braces from other JS in core? :)

Other locations: toolbar.module, contextual.module (a little bit), ckeditor.module (a tiny bit), dropbutton, matchmedia, drupal.js, displace.js, debounce.js.

nod_’s picture

webchick’s picture

Title: displace.js followup: Update documentation to follow Doxygen format » Update JS documentation to follow Doxygen format (remove curly braces)

Re: #5 ... Yes.

rteijeiro’s picture

Component: toolbar.module » javascript
Assigned: Unassigned » rteijeiro
Status: Active » Needs review
FileSize
37.81 KB

I have created a patch with the js documentation cleaning of the files in core. I guess I didn't forget anyone.

Also I hope the patch is right (it's my first patch)

Feedback is welcome.

jessebeach’s picture

rteijeiro thank you for the patch. It seems like you may have gotten more changes in your diff than just comments. Try rebasing your branch on the current 8.x branch, so that just the changes you made are present and not any changes from when you created your branch to the time that you created the diff. Does that makes sense?

Status: Needs review » Needs work

The last submitted patch, update-js-documentation-1958246-8.patch, failed testing.

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
51.52 KB

Hi Jesse, sorry for the mistake. I fetched and rebased with 8.x branch. Hope the patch is now right. If not, just notify me again ;)

Status: Needs review » Needs work

The last submitted patch, update-js-documentation-1958246-11.patch, failed testing.

rteijeiro’s picture

Sorry, this patch is crappy again. I will try to fix it.

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
17.13 KB

I guess now I did the diff with the correct branch :)

Wim Leers’s picture

Status: Needs review » Needs work
+++ b/core/misc/displace.jsundefined
@@ -34,11 +34,11 @@
-   * @param {boolean} broadcast
+   * @param boolean broadcast

Should be uppercased.

+++ b/core/misc/displace.jsundefined
@@ -34,11 +34,11 @@
-   * @return {object}
+   * @return object

Idem.

+++ b/core/misc/displace.jsundefined
@@ -54,7 +54,7 @@
-   * @return {object}
+   * @return object

Idem.

(And several more of these. I checked with nod_ to make sure that's the goal.)

+++ b/core/modules/toolbar/js/toolbar.menu.jsundefined
@@ -96,10 +95,9 @@ var activeItem = drupalSettings.basePath + drupalSettings.currentPath;
+     * @param Integer level

"Integer" does not exist in JavaScript. This should be "Number".

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
21.87 KB

Also did the following changes:

- Uppercased 'string' to 'String'.
- Uppercased 'number' to 'Number'.
- Changed 'bool' by 'Boolean'.

Wim Leers’s picture

Status: Needs review » Needs work

Awesome! I wanted to RTBC, but there's just one more thing…

+++ b/core/misc/ui/external/qunit.jsundefined
@@ -40,8 +40,9 @@ var QUnit,
+	 * @param String|Error error
+   *
+	 * @return String error message

We shouldn't be changing external libraries.

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
20.09 KB

It's true. I didn't realized about that :)

Fixed.

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, thanks! :)

rteijeiro’s picture

Great!! My first patch ^_^

Thanks, guys!!

jessebeach’s picture

Looks great, thank you so much rteijeiro!!!!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Needs a re-roll

error: patch failed: core/misc/drupal.js:283
error: core/misc/drupal.js: patch does not apply
rteijeiro’s picture

Status: Needs work » Needs review
FileSize
20.06 KB

Rerolled.

Please, tell me if everything is ok.

star-szr’s picture

Issue tags: -JavaScript, -Novice

Status: Needs review » Needs work
Issue tags: +JavaScript, +Novice

The last submitted patch, update-js-documentation-1958246-23.patch, failed testing.

star-szr’s picture

Needs another reroll…

rteijeiro’s picture

Status: Needs work » Needs review
FileSize
13.28 KB

Rerolled with the latest changes in 8.x branch.

Status: Needs review » Needs work
Issue tags: -JavaScript, -Novice

The last submitted patch, update-js-documentation-1958246-27.patch, failed testing.

rteijeiro’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, update-js-documentation-1958246-27.patch, failed testing.

star-szr’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, update-js-documentation-1958246-27.patch, failed testing.

rteijeiro’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript, +Novice
star-szr’s picture

Status: Needs review » Needs work

I just reviewed the patch and did some grepping and this looks quite good to me.

find core ! -path */external/* ! -name jquery.js -type f -name *.js -exec grep -nH " \* @.*{.*}" {} \; | grep -v inheritdoc

I found a few curly braces in ckeditor.admin.js that can be cleaned up:

/**
 * Returns a string describing the type and index of a toolbar row.
 *
 * @param {jQuery} $row
 *   A jQuery object containing a .ckeditor-button row.
 *
 * @return {String}
 *   A string describing the type and index of a toolbar row.
 */
/**
 * Applies or removes the focused class to a toolbar row.
 *
 * When a button in a toolbar is focused, focus is triggered on the containing
 * toolbar row. When a row is focused, the state change is announced through
 * the aria-live message area.
 *
 * @param {jQuery} event
 *   A jQuery event.
 */

And one in tableheader.js:

/**
 * Store the state of TableHeader.
 */
$.extend(TableHeader, {
  /**
   * This will store the state of all processed tables.
   *
   * @type {Array}
   */
  tables: []
});
rteijeiro’s picture

Great command, @Cottser, thanks!

Updated the patch according the #34 comment.

rteijeiro’s picture

Status: Needs work » Needs review

Forgot needs review status :(

cilefen’s picture

A grep through all the core js shows all curly braces are accounted for by update-js-documentation-1958246-35.patch in comment #35.

star-szr’s picture

I think this is RTBC once it comes back green, quite a queue right now though.

Status: Needs review » Needs work
Issue tags: -JavaScript, -Novice

The last submitted patch, update-js-documentation-1958246-35.patch, failed testing.

rteijeiro’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript, +Novice
star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Great work @rteijeiro :)

rteijeiro’s picture

Thanks Cottser :)

Hope it will be merged before someone changes one of those files :P

nod_’s picture

This patch makes jsdoc useless btw. Not sure how important that is but it's too bad.

rteijeiro’s picture

nod_’s picture

yeah don't get me started on that one.

The thing is that with the default jsdoc template, without the {} it will think the type is actually the name of the variable and we end up with documentation like annonce(String, String) instead of annonce(text, priority).

Also if we want to rely on a documentation tool and not having to write our own, we have to go with JSDoc. If it's good enough for google, it's good enough for us: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?sh...

If someone wants to write a doxygen parser for JS sure, we can go with that. Won't be me though and I'd like JS docs in the near future, either as jsdoc output or on api.d.o, whichever comes first.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Sounds like this needs more discussion?

cilefen’s picture

Definitely. If Doxygen isn't an option for javascript it probably doesn't make sense to comment in its style.

If that is true about Doxygen then we'd be better off going with the best available JS documenter and writing a Drupal standards filter for it if necessary.

One of the key questions is whether we could integrate its output with the PHP file documentation.

nod_’s picture

@cilefen that has been worked on by attiks: #1337022-80: [policy, no patch] Create/adopt JavaScript docs standards compatible with a JS documentation parser and his proof of concept is still online: http://drupalapi.attiks.com/api/js-samples/files/7 since JS is so different than PHP there are a few concepts that can't be properly handled by the api module.

nod_’s picture

Issue summary: View changes

Add link to JS coding standards

parthipanramesh’s picture

Issue summary: View changes

patch failes..

error: patch failed: core/modules/ckeditor/js/ckeditor.admin.js:249
error: core/modules/ckeditor/js/ckeditor.admin.js: patch does not apply
error: core/modules/contextual/contextual.toolbar.js: No such file or directory
error: core/modules/overlay/overlay-parent.js: No such file or directory
error: patch failed: core/modules/toolbar/js/toolbar.js:168
error: core/modules/toolbar/js/toolbar.js: patch does not apply
error: patch failed: core/modules/toolbar/js/toolbar.menu.js:68
error: core/modules/toolbar/js/toolbar.menu.js: patch does not apply
nod_’s picture

Status: Needs review » Closed (won't fix)

About this issue: No.

Patch to come in another issue. I'll link to it once patch is up.