10
45
Fork
You've already forked doipjs
28

Fix and improve JSdoc types #70

Merged
yarmo merged 6 commits from fix-jsdoc-types into dev 2024年01月29日 23:53:17 +01:00
Owner
Copy link

This PR removes all of the TS-idiomatic types and fixes all the JSDoc types. New types are introduced to eliminate as much as possible the use of "plain" object types.

Additional JSDoc tags are introduced to improve the generated docs.

This PR adds the jsdoc plugin for eslint to help with the detection of JSdoc issues.

Open issue to be fixed by later PR: type importing and exporting is finnicky. This PR introduces a new module "Types" with the sole purpose of holding pure-JSDoc type definitions. This works flawlessly with type checking while programming. However, they don't result in "clickable" types when generating the docs. Minor inconvenience but would be nice to fix.

This PR removes all of the TS-idiomatic types and fixes all the JSDoc types. New types are introduced to eliminate as much as possible the use of "plain" object types. Additional JSDoc tags are introduced to improve the generated docs. This PR adds the `jsdoc` plugin for eslint to help with the detection of JSdoc issues. **Open issue to be fixed by later PR**: type importing and exporting is finnicky. This PR introduces a new module "Types" with the sole purpose of holding pure-JSDoc type definitions. This works flawlessly with type checking while programming. However, they don't result in "clickable" types when generating the docs. Minor inconvenience but would be nice to fix.
yarmo force-pushed fix-jsdoc-types from 50218d4951
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
to 38323bc82a
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
2024年01月28日 13:55:54 +01:00
Compare
Ryuno-Ki left a comment
Copy link

You're almost there 😸

You're almost there 😸
@ -7,1 +7,3 @@
"extends": "standard",
"extends": [
"standard",
"plugin:jsdoc/recommended"
Owner
Copy link

Could become another issue.

ESLint is moving to FlatConfig:

https://eslint.org/blog/2023/11/whats-coming-in-eslint-9.0.0/

This PR is already large enough. Shall I file another issue for it?

Could become another issue. ESLint is moving to FlatConfig: https://eslint.org/blog/2023/11/whats-coming-in-eslint-9.0.0/ This PR is already large enough. Shall I file another issue for it?
Author
Owner
Copy link

Thanks for the link, looked at it, still not entirely sure what flat config is. In any case, eslint 9.0.0 is not out yet so let's keep the config change for a different PR. Do file an issue for it!

Thanks for the link, looked at it, still not entirely sure what flat config is. In any case, eslint 9.0.0 is not out yet so let's keep the config change for a different PR. Do file an issue for it!
Owner
Copy link

Filed #72

Filed https://codeberg.org/keyoxide/doipjs/issues/72
tyy marked this conversation as resolved
@ -2,2 +2,4 @@
import { ServiceProviderDefinitions } from '../src/index.js'
const main = async () => {
const def = ServiceProviderDefinitions.data.activitypub.processURI('lo');
Owner
Copy link

This appears to be unused in the file.

This appears to be unused in the file.
Author
Owner
Copy link

Crap, always check all the files before committing... Fixed

Crap, always check all the files before committing... Fixed
yarmo marked this conversation as resolved
src/asp.js Outdated
@ -84,2 +83,3 @@
* @returns {Promise<Profile>} The extracted profile
* @example
* const key = doip.aspe.parseProfileJws('...');
* const key = await doip.aspe.parseProfileJws('...');
Owner
Copy link

You might want to pass in two strings as both are required.

You might want to pass in two strings as both are required.
yarmo marked this conversation as resolved
src/claim.js Outdated
@ -80,3 +79,2 @@
* @function
* @param {object} claimObject
* @returns {Claim | Error}
* @param {object} claimObject - JSON representation of a claim
Owner
Copy link

Be aware that there's a difference between @param {object} (a literal: {}) and @param {*} (that is: any) in JSDoc.

My hunch is that you want * here.

Be aware that there's a [difference](https://jsdoc.app/tags-type) between `@param {object}` (a literal: `{}`) and `@param {*}` (that is: `any`) in JSDoc. My hunch is that you want `*` here.
yarmo marked this conversation as resolved
src/claim.js Outdated
@ -81,2 +80,2 @@
* @param {object} claimObject
* @returns {Claim | Error}
* @param {object} claimObject - JSON representation of a claim
* @returns {Claim | Error} Parsed claim
Owner
Copy link

It doesn't return an Error, but throws it.

It doesn't _return_ an Error, but [throws](https://jsdoc.app/tags-throws) it.
yarmo marked this conversation as resolved
src/claim.js Outdated
@ -245,6 +244,7 @@ export class Claim {
let claimData = this._matches[index]
/** @type {import('./types').VerificationResult} */
Owner
Copy link

Should also indiciate | null to avoid Null Pointer Exceptions.

Should also indiciate `| null` to avoid Null Pointer Exceptions.
yarmo marked this conversation as resolved
src/defaults.js Outdated
@ -42,2 +24,2 @@
* @property {string|null} claims.xmpp.username - The username used to log in
* @property {string|null} claims.xmpp.password - The password used to log in
* The default claim verification config used throughout the library
* @constant
Owner
Copy link

This might be superfluous (the const variable declaration should allow to infer this)

This might be superfluous (the `const` variable declaration should allow to infer this)
yarmo marked this conversation as resolved
@ -14,2 +14,4 @@
limitations under the License.
*/
/**
* Fetch proofs from {@link module:profile~Profile} obtained through ASPE
Owner
Copy link

Is this notation to reference still required with the plugin you installed?

Is this notation to reference still required with the plugin you installed?
Author
Owner
Copy link

Using this notation somehow did not create link, remove the module: notation and now the link works, nice find

Using this notation somehow did not create link, remove the `module:` notation and now the link works, nice find
Author
Owner
Copy link

Ah, that's right. eslint didn't like it without the module:. Ah well, getting rid of the whole link tag

--edit

I got rid of the link. I'll let you resolve this conversation if this solution suits you too

Ah, that's right. eslint didn't like it without the `module:`. Ah well, getting rid of the whole link tag --edit I got rid of the link. I'll let you resolve this conversation if this solution suits you too
Owner
Copy link

Sure. Let's roll with this and wait for feedback.

Sure. Let's roll with this and wait for feedback.
Ryuno-Ki marked this conversation as resolved
@ -29,3 +51,1 @@
service,
username,
password
service: params.service,
Owner
Copy link

const xmpp = client({ ...params }) might also work.

`const xmpp = client({ ...params })` might also work.
Author
Owner
Copy link

Ah, so that's how that works. Indeed works

Ah, so that's how that works. Indeed works
Owner
Copy link

In case you want to learn more: Spread syntax

In case you want to learn more: [Spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)
yarmo marked this conversation as resolved
@ -61,0 +74,4 @@
* @param {string} data.id - The identifier of the targeted account
* @param {number} [data.fetcherTimeout] - Optional timeout for the fetcher
* @param {import('../types').VerificationConfig} [opts] - Options used to enable the request
* @returns {Promise<Array<string>>} The fetched proofs from an XMPP account
Owner
Copy link

I'd recommend to either stick to string[] or Array<string> notation.

I'd recommend to either stick to `string[]` or `Array<string>` notation.
Author
Owner
Copy link

Changed everything to Array<Type>

Changed everything to `Array<Type>`
yarmo marked this conversation as resolved
@ -35,2 +34,2 @@
* @param {string} [keyserverDomain=keys.openpgp.org] - Domain of the keyserver
* @returns {Promise<Profile>}
* @param {string} identifier - Fingerprint or email address
* @param {string} [keyserverDomain] - Domain of the keyserver
Owner
Copy link

You can even document the default value:

@param {string}] [keyserverDomain='keys.openpgp.org'] - Domain of the keyserver

Strictly speaking it's the hostname.

You can even document the default value: `@param {string}] [keyserverDomain='keys.openpgp.org'] - Domain of the keyserver` Strictly speaking it's the hostname.
Author
Owner
Copy link

eslint says no (that's why I removed it in this PR):

 35:1 warning Defaults are not permitted on @param jsdoc/no-defaults

This rule baffles me, jsdoc documentation clearly states default values exist

`eslint` says no (that's why I removed it in this PR): ``` 35:1 warning Defaults are not permitted on @param jsdoc/no-defaults ``` This rule baffles me, jsdoc documentation clearly states default values exist
Member
Copy link

As per https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.README/rules/no-defaults.md, it is not that defaults don't exist but rather that the default could be inferred in this situation as it is explicitly defined with es6 notation

As per https://github.com/gajus/eslint-plugin-jsdoc/blob/main/.README/rules/no-defaults.md, it is not that defaults don't exist but rather that the default could be inferred in this situation as it is explicitly defined with es6 notation
Author
Owner
Copy link

Alright, then we can mark this as resolved because I did add the default value using es6 notation

Alright, then we can mark this as resolved because I did add the default value using es6 notation
Ryuno-Ki marked this conversation as resolved
@ -20,3 +19,3 @@
* @class
* @constructor
* @classdesc A persona with identity claims
* @public
Owner
Copy link

@public should be the default and therefore is not needed.

`@public` should be the default and therefore is not needed.
yarmo marked this conversation as resolved
@ -15,1 +15,4 @@
*/
/**
* ASPE service provider
*
Owner
Copy link

I very much prefer a blank line between the subject and the description of a doclet. However, you don't follow this everywhere, so you might want to be consistent.

I very much prefer a blank line between the subject and the description of a doclet. However, you don't follow this everywhere, so you might want to be consistent.
Author
Owner
Copy link

We could add a blank line in all the places, is fine by me. However, this is not a blank line between subject and description:

 * ASPE service provider
 *
 * Link: [Keyoxide documentation](https://docs.keyoxide.org/service-providers/aspe/)

This was simply a blank line to separate two lines of the header. I used markdown's usual two spaces but then the linter yelled at me. I'll turn it into line with @link

We could add a blank line in all the places, is fine by me. However, this is not a blank line between subject and description: ``` * ASPE service provider * * Link: [Keyoxide documentation](https://docs.keyoxide.org/service-providers/aspe/) ``` This was simply a blank line to separate two lines of the header. I used markdown's usual two spaces but then the linter yelled at me. I'll turn it into line with `@link`
yarmo marked this conversation as resolved
@ -16,0 +16,4 @@
/**
* ASPE service provider
*
* Link: [Keyoxide documentation](https://docs.keyoxide.org/service-providers/aspe/)
Owner
Copy link

Might as well be a @link.

Might as well be a [`@link`](https://jsdoc.app/tags-inline-link).
yarmo marked this conversation as resolved
@ -0,0 +1,197 @@
/*
Copyright 2024 Yarmo Mackenbach
Owner
Copy link

You might want to add a @license for good measure.

You might want to add a [`@license`](https://jsdoc.app/tags-license) for good measure.
Author
Owner
Copy link

Added a @license to the module in index.js. I assume this is sufficient? We could add it to every module if that's preferred

Added a `@license` to the module in `index.js`. I assume this is sufficient? We could add it to every module if that's preferred
Owner
Copy link

I'll leave it as is and see what feedback comes in. If you were to add it to every file, @author, @copyright etc. could be added as well. Not sure whether people will consider it important.

Perhaps ask for feedback once the new documentation is live.

I'll leave it as is and see what feedback comes in. If you were to add it to every file, [`@author`](https://jsdoc.app/tags-author), [`@copyright`](https://jsdoc.app/tags-copyright) etc. could be added as well. Not sure whether people will consider it important. Perhaps ask for feedback once the new documentation is live.
Ryuno-Ki marked this conversation as resolved
@ -0,0 +32,4 @@
/**
* Details about the service provider
* @typedef {object} ServiceProviderAbout
* @property {string} id - Identifier of the service provider (no whitespace or symbols, lowercase)
Owner
Copy link

You could go even further and use a type union (e.g. 'activitypub' | 'xmpp' | ...) instead of a plain string).

This enables IntelliSense to make concrete suggestions.

You could go even further and use a type union (e.g. 'activitypub' | 'xmpp' | ...) instead of a plain `string`). This enables IntelliSense to make concrete suggestions.
Author
Owner
Copy link

This would be acceptable if there's a way to clarify that the list is non-exhaustive. ActivityPub software names that are dynamically fetched are also accepted values

This would be acceptable if there's a way to clarify that the list is non-exhaustive. ActivityPub software names that are dynamically fetched are also accepted values
Owner
Copy link

I see. Well, now you know. In case you run into some other place where it would be applicable.

I see. Well, now you know. In case you run into some other place where it would be applicable.
Ryuno-Ki marked this conversation as resolved
@ -224,3 +218,1 @@
* @param {string} params.proofEncodingFormat
* @param {string} [params.claimRelation]
* @returns {Promise<boolean>}
* @param {any} proofData - Data potentially containing the proof
Owner
Copy link

Usually denoted with @param {*} proofData in JSDoc.

Usually denoted with `@param {*} proofData` in JSDoc.
yarmo marked this conversation as resolved
@ -272,3 +267,3 @@
/**
* Run the verification by finding the formatted fingerprint in the proof
* Run the verification by searching for the proof in the fetched data
* @async
Owner
Copy link

You often don't include this in other functions.

You often don't include this in other functions.
Author
Owner
Copy link

Removed all @async

Removed all `@async`
yarmo marked this conversation as resolved
yarmo force-pushed fix-jsdoc-types from 38323bc82a
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
to f8d0422443
All checks were successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pull_request_closed/test Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
2024年01月29日 14:06:00 +01:00
Compare
Author
Owner
Copy link

Thanks for the review @Ryuno-Ki, I left five review comments open for you to respond or resolve.

Thanks for the review @Ryuno-Ki, I left five review comments open for you to respond or resolve.

Left my comments.

Left my comments.
Author
Owner
Copy link

Thanks! If there are no more comments, I'll merge tonight

Thanks! If there are no more comments, I'll merge tonight
Sign in to join this conversation.
No reviewers
Labels
Clear labels
bug
Something is not working

Archived

enhancement
New feature

Archived

Contribution welcome
Get started contributing here
Good first issue
Good if you are new to the project or to open source contributions
Impact
External
Affects the people using the project
Impact
Internal
Affects on the people working on the project
Priority
Critical
Work on right now
Priority
High
Work on at earliest convenience
Priority
Low
Work on in spare time
Priority
Medium
Work on regularly
Review
Duplicate
Already exists
Review
Off Topic
Does not fall within the scope of the repo/project
Status
Backlog
Is not being worked on yet
Status
Blocked
Is waiting on something or someone
Status
Completed
Is done
Status
In Progress
Is being worked on
Status
Investigating
Is waiting on research or questions
Status
Needs Decision
Is waiting on a decision by the devs/contributors
Status
Needs Info
Is waiting on additional information before it can be solved
Status
Needs Triage
Is new issue that needs reviewing
Status
Testing
Is being checked and verified
Status
Waiting For Review
Is waiting on reviewers to approve
Status
Won't Fix
Won't be fixed
Type
Bug
Related to something not working as intended
Type
CI
Related to continuous integration
Type
Documentation
Related to documentation
Type
Enhancement
Related to a new feature or an improved one
Type
New Claim
Related to a new identity claim/proof
Type
Security
Related to security
Type
Tests
Related to code tests
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
keyoxide/doipjs!70
Reference in a new issue
keyoxide/doipjs
No description provided.
Delete branch "fix-jsdoc-types"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?