Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the jsdoc comments to modern syntax - Part 1 #3694

Merged
merged 3 commits into from
Dec 2, 2016
Merged

Update the jsdoc comments to modern syntax - Part 1 #3694

merged 3 commits into from
Dec 2, 2016

Conversation

brandonocasey
Copy link
Contributor

@brandonocasey brandonocasey commented Oct 19, 2016

Description

  • Add @return and description where missing from functions
  • Add @param and description where missing
  • Remove un-necessary doc comments such as @class and @method
  • Update examples to match current code standards
  • Update descriptions to make more sense across the board
  • Keep all doc comments in a standard format
  • Verify that documentation looked good after running jsdoc
  • document @events and @fires
  • Depends upon remove un-needed contructor and function overrides #3721

Requirements Checklist

  • Feature implemented / Bug fixed
  • Reviewed by Two Core Contributors

Copy link
Member

@misteroneill misteroneill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A number of grammar and other questions/concerns.

@@ -32,14 +35,19 @@ class BigPlayButton extends Button {
/**
* Handles click for play
*
* @method handleClick
* @return {undefined}
* n/a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced we should have an @return tag for functions that don't explicitly return anything (i.e. undefined). That seems like a feature of the language rather than something we need to document.

* The class name or instance of a child to add
*
* @param {Object} [options={}]
* including options to be passed to children of the child.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we lose "Options, " here?

* @return {Element}
* @method createEl
* the element that was created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this isn't implied by the fact that we have @return {Element}... maybe. I'm torn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be implied but I don't think its a bad thing to document

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization, though. 😄

@@ -110,8 +127,8 @@ class ClickableComponent extends Component {
/**
* Allows sub components to stack CSS class names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make much sense. It's like it's describing why the method exists - not what it does. I think something like: "Constructs a string to be used for the component's element's className." would be preferable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a why isn't necessary bad, though, it should be done in a secondary paragraph or something. The first thing should definitely be what it does.

* @return {String}
* @method buildCSSClass
* @return {string}
* The current css class for this ClickableComponent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel particularly accurate. It returns the default className for the component's element - not the current className. I think we should avoid using the term "css class" because it's got nothing to do with CSS.

*/
setTimeout(fn, timeout) {
fn = Fn.bind(this, fn);

// window.setTimeout would be preferable here, but due to some bizarre issue with Sinon and/or Phantomjs, we can't.
// window.setTimeout would be preferable here,
// but due to some bizarre issue with Sinon and/or Phantomjs, we can't.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is relevant anymore.

*/
static getComponent(name) {
if (Component.components_ && Component.components_[name]) {
return Component.components_[name];
}

// TODO: deprecated?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the question here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to warn in the log that this is deprecated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably something that should just be disallowed/removed in 6.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I will add an @deprication tag to the function here

@@ -49,6 +49,11 @@ class ErrorDisplay extends ModalDialog {
}
}

/**
* Available options for an error display
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be "Default options" instead of "Available options".

*/
import * as Events from './utils/events.js';

/**
* An EventTarget class that seeks to emulate much of the builtin
* HTML EventTarget functionalify as well as add all kinds of ease
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "functionalify" and I think the sentence can end there. The rest is kind of vague.

EventTarget.prototype.allowedEvents_ = {};

/**
* This function is a cross browser wrapper around addEventListener
* with a much nicer syntax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to describe what this does rather than its implementation, the same way the off method does.

@brandonocasey brandonocasey changed the title updated all docs to follow modern jsdoc 3 standards Update the jsdoc comments to modern syntax - Part 1 Oct 20, 2016
Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff.

constructor(player, options) {
super(player, options);
this.controlText(options && options.controlText || this.localize('Close'));
}

/**
* Constructs a string to be used for the component elements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does jsdoc not provide any functionality for inheritance? So we would only need to document these in Component and then everything would be linked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything that you override needs to be documented, we get anything that is not overridden, in the docs for the object. There are ways to say that this method should use the parents doc comments, but doing so causes jsdoc to link to the parent function rather than the current files function (so it seems like the current file does not implement it)

* @param {Event|Object|string} event
* A string (the type) or an event object with a type attribute
*
* @param {Object} [hash]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an "optional" indicator?

Copy link
Contributor Author

@brandonocasey brandonocasey Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets [] around the parameter indicate optional

* 'width' or 'height'
*
* @return {number|boolean}
8 the dimention or false if nothing was set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 instead of *.
dimension mispelled.

This doesn't return a boolean. It should default to 0, I believe.

*/
static getComponent(name) {
if (Component.components_ && Component.components_[name]) {
return Component.components_[name];
}

// TODO: deprecated?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably something that should just be disallowed/removed in 6.0

@@ -27,11 +30,10 @@ class ErrorDisplay extends ModalDialog {
/**
* Include the old class for backward-compatibility.
*
* This can be removed in 6.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what this refers to specifically.

@brandonocasey
Copy link
Contributor Author

@gkatsev @misteroneill ready for re-review

misteroneill
misteroneill previously approved these changes Oct 25, 2016
@misteroneill misteroneill dismissed their stale review October 25, 2016 14:58

Starting a new review!

@misteroneill
Copy link
Member

As a general comment, I think it'd be good to have some kind of conventions regarding grammar. My personal feeling is that things should generally follow English grammar. So, something like this:

* @return {Component}
*         Returns itself; method can be chained.

But that's me. If more people disagree, that's fine. Thoughts?

@brandonocasey
Copy link
Contributor Author

sounds good to me

Copy link
Member

@misteroneill misteroneill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started adding individual line comments, but I think the whole thing could use a grammar sweep. Unless someone disagrees, I believe documentation should follow the conventions of the language in which it's written.

* @return {String} The constructed class name
* @method buildCSSClass
* @return {string}
* returns default class name ie. 'vjs-big-play-button'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple grammatical updates here: Returns default class name, i.e., 'vjs-big-play-button'.

constructor(player, options) {
super(player, options);
}

/**
* Allow sub components to stack CSS class names
* Get the default css class for the BigPlayButton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're leaving "css" here it should be capitalized.

*
* @param {Object} [options]
* Object of option names and values
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both "constructor" and "the" should be capitalized in this block.

* Constructor for Button
*
* @param {Player} player
* the player to attach this button to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization.

*
* @method handleKeyPress
* @param {Event} event
* the button event that caused this function to be called
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization.

* @return {Element}
* @method controlText
* the control text element
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably stand to have some capitalization added to both the @return and the description above.

*
* @return {string|ClickableComponent}
* - The control text when getting
* - Returns itself when setting; method can be chained.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get Markdown-ified?

* @return {String}
* @method buildCSSClass
* @return {string}
* the default className for a component
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization and sentences should end in periods.

* @method handleKeyPress
* @param {Event} event
* the event that caused this to be called, in most cases
* this will be the `keydown` event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave out everything after the comma. And capitalize.

* var button = player.addChild('button');
*
* console.log(button.el());
* // will have the same html result as the previous example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should really have code examples in API docs or leave that to the manual documentation/guides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A part of me feels like we need to have doc comments that link to guides, and the guides should be the ones with the examples. Maybe another PR to rip examples out into manual documentation at a later date?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an upside to have examples here:

  1. more likely to get updated if things change
  2. A user doesn't have to go to a guide to read up on how to use it

But I'm ok with moving it to a guide and linking it here in a separate PR pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another benefit of having the jsdoc comments not contain examples. Is that we can lint markdown examples with eslint. Which cannot be done with jsdoc markdown examples.

* This gets called when a `ClickableComponent` gets:
* - Clicked (via the `click` event, listening starts in the constructor)
* - Tapped (via the `tap` event, listening starts in the constructor)
* - Gains focus (via the `focus` event). Causes `ClickableComponent`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't listen to keydown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When focus is triggered handleFocus is called.

* This gets called when a `CloseButton` gets:
* - Clicked (via the `click` event, listening starts in the constructor)
* - Tapped (via the `tap` event, listening starts in the constructor)
* - Gains focus (via the `focus` event). Causes `ClickableComponent`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

* var button = player.addChild('button');
*
* console.log(button.el());
* // will have the same html result as the previous example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an upside to have examples here:

  1. more likely to get updated if things change
  2. A user doesn't have to go to a guide to read up on how to use it

But I'm ok with moving it to a guide and linking it here in a separate PR pass

* Whenever a property is an object on both options objects
* the two properties will be merged using mergeOptions.
* Deep merge of options objects with new options.
* > Note: When a property of is an object on both `obj` and `options`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"When a property of is an object" is weird.
Maybe something like:
When both obj and options contain a property whose value is an object, the two properties get merged using mergeOptions

* - `otherComponent.on('eventName', myFunc)`
* Is that the listeners will get cleaned up when either component gets disposed.
* It will also bind `myComponent` as the context of `myFunc`.
* > **NOTE**: If you remove the element from the DOM that has used `on` you need to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think usage of NOTE is consistent.

@@ -1378,12 +1711,16 @@ class Component {
}

/**
* Registers a component
* Register a `Component` with `videojs` given the name and the component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a note that Techs shouldn't be registered as Components?

*
* @typedef {Object} EventTarget~Event
* @see [Properties]{@link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent}
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line, please

*
* @param {Object} [hash]
* hash of data sent during the event
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line, please

*/
/**
* An object containing event names as keys and true/false values as values. If an
* event name is set to a true value here {@link EventTarget#trigger} will have extra.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence is incomplete. What will trigger have extra of?

*
* If the name of the Event that is being triggered is in `EventTarget.allowedEvents_`
* then trigger will also call the `on` + `uppercaseEventName` function. Example:
* the 'click' is in in `EventTarget.allowedEvents_` trigger will attempt to call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click is in allowedEvents_, so, trigger will attempt to call onclick if it exists.

added docs where missing
updated examples where broken or where they did not make sense
eslinted with eslint-plugin-jsdoc
change @link to @see
better @return descriptions for chainable methods
ran hemmingway over the jsdoc comments
custom event type
custom callback types
better @Listens, @fires, and @event documentation
made jsdoc recursive
@gkatsev gkatsev modified the milestone: 5.14 Nov 15, 2016
@gkatsev gkatsev merged commit 1a0b281 into videojs:master Dec 2, 2016
@brandonocasey brandonocasey deleted the chore/modernize-docs-1 branch December 6, 2016 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants