-
Notifications
You must be signed in to change notification settings - Fork 215
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
base: master
Are you sure you want to change the base?
Conversation
* @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. |
There was a problem hiding this comment.
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.
@@ -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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
* promise). | ||
* | ||
* @param {Promise<any>} promise | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converted comment to JSDoc.
There was a problem hiding this 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.
* 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] |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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] |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
webextension-polyfill/.eslintrc
Lines 19 to 32 in 949f08c
"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] |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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 It can however be checked using ² 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. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
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). |
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)