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

typings: add typing for string decoder #38229

Merged
merged 4 commits into from
Dec 30, 2021

Conversation

Ayase-252
Copy link
Member

This PR adds some JSDoc typings for internal/string_decoder.

Screenshots from my VS code:

normalizeEncoding
Screen Shot 2021-04-13 at 23 35 26

StringDecoder
Screen Shot 2021-04-13 at 23 36 31

StringDecoder.prototype.write
Screen Shot 2021-04-13 at 23 37 00

StringDecoder.prototype.end
Screen Shot 2021-04-13 at 23 38 24

StringDecoder.prototype.text
Screen Shot 2021-04-13 at 23 37 34

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. string_decoder Issues and PRs related to the string_decoder subsystem. labels Apr 13, 2021
Copy link
Member Author

@Ayase-252 Ayase-252 left a comment

Choose a reason for hiding this comment

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

I know the line violates the maximum line length, but I couldn’t come up with a good idea to fix it. 🤔

/**
*
* @param {string} enc
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | "base64" | "latin1" | "base64url"}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | "base64" | "latin1" | "base64url"}
* @returns {"utf8" | "utf16le" | "hex" | "ascii"
* | "base64" | "latin1" | "base64url"}

What about this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, it works

Co-authored-by: Michaël Zasso <targos@protonmail.com>
lib/string_decoder.js Show resolved Hide resolved
Copy link
Member

@marsonya marsonya left a comment

Choose a reason for hiding this comment

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

I would suggest adding function descriptions in the jsdoc comments.

@@ -84,6 +99,11 @@ StringDecoder.prototype.write = function write(buf) {
return decode(this[kNativeDecoder], buf);
};

/**
*
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*
* Returns any remaining input stored in the internal buffer as a string.
* After end() is called, the stringDecoder object can be reused for new input.

@@ -68,12 +74,21 @@ for (let i = 0; i < encodings.length; ++i)
// StringDecoder provides an interface for efficiently splitting a series of
// buffers into a series of JS strings without breaking apart multi-byte
// characters.
/**
*
Copy link
Member

Choose a reason for hiding this comment

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

Move the above description inside the comment?

function StringDecoder(encoding) {
this.encoding = normalizeEncoding(encoding);
this[kNativeDecoder] = Buffer.alloc(kSize);
this[kNativeDecoder][kEncodingField] = encodingsMap[this.encoding];
}

/**
*
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
*
* Returns a decoded string, omitting any incomplete multibyte
* characters at the end of the Buffer, or TypedArray, or DataView

@Ayase-252 Ayase-252 changed the title typings: add typing for internal/string_decoder typings: add typing for string decoder Apr 20, 2021
Co-authored-by: marsonya <akhil.marsonya27@gmail.com>
Copy link
Member

@marsonya marsonya left a comment

Choose a reason for hiding this comment

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

Mark optional params as such and assign default value using JSDoc conventions.

Kindly ignore it incase this is too much detailing. I know we don't want to duplicate the documentation here using JSDoc. I just feel that it would be important information for core developers to know whether a param is optional or not and what it's default value would be.

lib/string_decoder.js Outdated Show resolved Hide resolved
lib/string_decoder.js Outdated Show resolved Hide resolved
@Ayase-252
Copy link
Member Author

Good idea, I will address optional arugment issue

Co-authored-by: Akhil Marsonya <akhil.marsonya27@gmail.com>
@Mesteery Mesteery removed the needs-ci PRs that need a full CI run. label Oct 12, 2021
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

RSLGTM

@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Dec 30, 2021
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 30, 2021
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/38229
✔  Done loading data for nodejs/node/pull/38229
----------------------------------- PR info ------------------------------------
Title      typings: add typing for string decoder (#38229)
Author     Qingyu Deng  (@Ayase-252)
Branch     Ayase-252:feature/typing-lib-internal-cipher -> nodejs:master
Labels     string_decoder, typings, commit-queue-squash
Commits    4
 - typings: add typing for internal/string_decoder
 - fixup: typings: add typing for internal/string_decoder
 - fixup: add function description
 - fixup: mark optional parameters
Committers 1
 - Qingyu Deng 
PR-URL: https://github.com/nodejs/node/pull/38229
Reviewed-By: James M Snell 
Reviewed-By: Antoine du Hamel 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/38229
Reviewed-By: James M Snell 
Reviewed-By: Antoine du Hamel 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 13 Apr 2021 15:40:00 GMT
   ✔  Approvals: 2
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/38229#pullrequestreview-640365320
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/38229#pullrequestreview-842115810
   ✔  Last GitHub CI successful
   ✖  No Jenkins CI runs detected
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/1639087835

@nodejs-github-bot nodejs-github-bot added the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Dec 30, 2021
@aduh95 aduh95 merged commit a100a93 into nodejs:master Dec 30, 2021
@aduh95
Copy link
Contributor

aduh95 commented Dec 30, 2021

Landed in a100a93

targos pushed a commit that referenced this pull request Jan 14, 2022
PR-URL: #38229
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Jan 31, 2022
PR-URL: #38229
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Linkgoron pushed a commit to Linkgoron/node that referenced this pull request Jan 31, 2022
PR-URL: nodejs#38229
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
danielleadams pushed a commit that referenced this pull request Feb 1, 2022
PR-URL: #38229
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@danielleadams danielleadams mentioned this pull request Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. string_decoder Issues and PRs related to the string_decoder subsystem. typings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants