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

docs: Improve JSDoc of browser‑polyfill.js functions and types #171

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ExE-Boss
Copy link
Contributor

A lot of the current JSDoc is straight up wrong or incomplete.

This corrects it to improve intellisense in VisualStudio Code when developing this polyfill.

review?(@Rob--W)

* @param {function(K):V} createItem
* A function which will be called in order to create the value for any
* key which does not exist, the first time it is accessed. The
* function receives, as its only argument, the key being created.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The createItem function documentation was moved to the correct location.

src/browser-polyfill.js Outdated Show resolved Hide resolved
@@ -109,19 +124,16 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object.
* The name of the method which is being wrapped.
* @param {object} metadata
* Metadata about the method being wrapped.
* @param {integer} metadata.minArgs
* @param {number} metadata.minArgs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to be set to number, as integer doesn’t exist.

* The maximum number of arguments which may be passed to the
* function. If called with more than this number of arguments, the
* wrapper will raise an exception.
* @param {integer} metadata.maxResolvedArgs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maxResolvedArgs hasn’t existed for a long time.

src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
* promise).
*
* @param {Promise<any>} promise
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converted comment to JSDoc.

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

This PR mixes some useful changes with changes of questionable value. Please make the following changes, and if you strongly disagree, show why the change is necessary anyway. Keeping unnecessary changes minimal makes it easier to use git blame to follow the history of the code.

Some of the changes only change the format of the JSDoc, but since there is no automatic validation of the formatting in the repo, they may go out of date in the future anyway since none of the main developers of this project are using your tools.

.eslintrc Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
* A function which will be called in order to create the value for any
* key which does not exist, the first time it is accessed. The
* function receives, as its only argument, the key being created.
* @param {ReadonlyArray<[K, V]>} [items]
Copy link
Member

Choose a reason for hiding this comment

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

Remove this @param. It doesn't help (perhaps we should remove the param altogether since it is never used - please do NOT make that change in this commit though).

Copy link
Member

Choose a reason for hiding this comment

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

The @param should be removed. My comment might have been ambiguous, when I said "please do not make that change", I was referring to the removal of the items parameter from the function.

Copy link
Contributor Author

@ExE-Boss ExE-Boss Feb 6, 2019

Choose a reason for hiding this comment

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

Removing this without also removing the items parameter would violate the valid‑jsdoc ESLint rule.

src/browser-polyfill.js Outdated Show resolved Hide resolved
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Another round of review. Please keep in mind that changes themselves need to be generally useful. We won't accept non-idiomatic changes that only exist to support your IDE. More comments = higher maintenance, and without automatic integration, these comments may eventually go out of date again.

src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Outdated Show resolved Hide resolved
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

The comments are getting in a better shape now. I'm still not too thrilled with the conversion fromProxy<object> and Proxy<function> to generics T and M. Since your goal is apparently to assist automatic parsing of the JSDoc rules, using TypeScript semantics, could you add a verification step to the build system that verifies that the JSDoc is valid? That's the only way to make sure that the work from this PR is not undone in later changes.

If that is not something that you'd like to do, then I would prioritize human readability over machine-readability, and prefer the use of Proxy<...> instead of generics.

* A function which will be called in order to create the value for any
* key which does not exist, the first time it is accessed. The
* function receives, as its only argument, the key being created.
* @param {ReadonlyArray<[K, V]>} [items]
Copy link
Member

Choose a reason for hiding this comment

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

The @param should be removed. My comment might have been ambiguous, when I said "please do not make that change", I was referring to the removal of the items parameter from the function.

src/browser-polyfill.js Outdated Show resolved Hide resolved
src/browser-polyfill.js Show resolved Hide resolved
Copy link
Contributor Author

@ExE-Boss ExE-Boss left a comment

Choose a reason for hiding this comment

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

JSDoc validation is already performed by ESLint:

"valid-jsdoc": [2, {
"prefer": {
"return": "returns",
},
"preferType": {
"Boolean": "boolean",
"Number": "number",
"String": "string",
"bool": "boolean",
},
"requireParamDescription": false,
"requireReturn": false,
"requireReturnDescription": false,
}],

Note that the only way full validity of the JSDoc comments could be enforced would be to migrate the code to TypeScript and then use a direct (esnext to esnext) conversion, but that’s out of scope of this PR.

* A function which will be called in order to create the value for any
* key which does not exist, the first time it is accessed. The
* function receives, as its only argument, the key being created.
* @param {ReadonlyArray<[K, V]>} [items]
Copy link
Contributor Author

@ExE-Boss ExE-Boss Feb 6, 2019

Choose a reason for hiding this comment

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

Removing this without also removing the items parameter would violate the valid‑jsdoc ESLint rule.

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

If you're not going to add automated verification, how can we verify that the JSDoc is in fact valid (without installing a full-blown IDE...)? The valid-jsdoc eslint rule isn't helping, because it accepts the JSDoc before and after your patch. So if in your eyes the JSDoc was invalid before the patch, then there should be some validator that shows a failing validation before, and a passing validation after the patch.

src/browser-polyfill.js Outdated Show resolved Hide resolved
@ExE-Boss
Copy link
Contributor Author

ExE-Boss commented Feb 7, 2019

Technically speaking, JSDoc can’t really be fully semantically validated¹ as it’s just documentation for developers based on the Javadoc syntax.


¹ It can be syntactically validated, which is what the valid‑jsdoc rule does, which ensures that all parameters and return values are documented.

It can however be checked using tsc, but that also checks a bunch of other TypeScript related stuff, and adding that to the pipeline as‑is² would just make the code unreadable without also converting to TypeScript.


² By that I mean using JavaScript and JSDoc to store type information instead of just using TypeScript directly, but as I said before, that’s out of scope of this PR.


That said, I still want to merge this.

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Before this PR, we only used very basic JSDoc annotations (with plain types such as function and string, with the most complicated type being Proxy<object>).
In this PR, you introduced new type annotations based on TypeScript. This raises the bar for contributing to the library, because others are now required to understand TypeScript syntax and its types.

function is clearly simpler than function(any):void, but the latter is also more precise in the expected types (unsurprisingly). I am willing to accept slightly more complicated syntax if there are clear benefits. Since you've taken the efforts to open this PR and repeatedly respond to reviews, I assume that you see benefits, such as better integration in your IDE. This integration relies on automated tooling, so there must be a way (automatically or manually) for me to verify that your annotations are "correct".

Types such as ReadonlyArray, PropertyKey and ProxyHandler<T> are only meaningful with TypeScript, and I'm not even sure if there is any JSDoc parser that can make sense of (message, sender: object, sendResponse: (response?: any) => void) => boolean | Promise<any> | void.

Either show a straightforward way to verify that the types are meaningful, or remove the TypeScript-specific syntax. And if you do decide to drop TypeScript, use Proxy<object> and Proxy<function> instead of T and M.

* The reply.
*
* When `reply.__mozWebExtensionPolyfillReject__` is defined and `true`,
* then the reply is a wrapped `Error` object.
Copy link
Member

Choose a reason for hiding this comment

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

Previously you said that using any would cause an error. If that is the case, consider rewording this line to:

then the reply is an object whose `message` property is set to the original error message.

and remove the two @param below.

src/browser-polyfill.js Show resolved Hide resolved
@Zearin
Copy link

Zearin commented Jan 20, 2020

Would love to see this merged. I like valid JSDoc.

I don’t like TypeScript, however. I don’t think it should be included in JSDoc (unlike the source code is written in TypeScript as well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants