-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
add jsdocs to tldr and cache #355
base: main
Are you sure you want to change the base?
Conversation
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.
Wow, I wonder why comment enhancements are left so long unmerged.
/** | ||
* Fetch a page from cache using preferred language and preferred platform. | ||
* @param page {} A | ||
* @returns {Promise<unknown>} |
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.
What is the difference between Promise<any>
and Promise<unknown>
?
// Return all commands for a given platform. | ||
// P.S. - The platform 'common' is always included. |
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.
Should we remove this then? Seems repeated.
@@ -21,6 +21,11 @@ class Tldr { | |||
this.cache = new Cache(this.config); | |||
} | |||
|
|||
/** | |||
* Print pages for a given platform.. |
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.
Multiple periods at the end of the sentence.
listAll(singleColumn) { | ||
return index.commands() | ||
.then((commands) => { | ||
return this.printPages(commands, singleColumn); | ||
}); | ||
} | ||
|
||
/** | ||
* Print a command page. | ||
* @param commands {string[]} A given command to be printed. |
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.
"A given command" is incorrect when we are passing an array. Let's change this to plural.
clearCache() { | ||
return this.cache.clear().then(() => { | ||
console.log('Done'); | ||
}); | ||
} | ||
|
||
/** | ||
* Update the cache. | ||
* @returns {Promise<any>} A promise with the index. |
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.
Should this be "A promise with the cache"?
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.
LGTM after we address the left concerns.
However, we can resolve just some of them and merge it, this PR adds documentation for quite a lot of functions. It's better to have a not ideal documentation than almost no documentation.
@@ -21,6 +21,11 @@ class Tldr { | |||
this.cache = new Cache(this.config); | |||
} | |||
|
|||
/** | |||
* Print pages for a given platform.. |
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.
* Print pages for a given platform.. | |
* Print pages for a given platform. |
listAll(singleColumn) { | ||
return index.commands() | ||
.then((commands) => { | ||
return this.printPages(commands, singleColumn); | ||
}); | ||
} | ||
|
||
/** | ||
* Print a command page. | ||
* @param commands {string[]} A given command to be printed. |
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.
* @param commands {string[]} A given command to be printed. | |
* @param commands {string[]} Given commands to be printed. |
* Return all commands for a given platform. | ||
* | ||
* The 'common' platform is always included. | ||
* @param platform {string} The platform. |
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.
* @param platform {string} The platform. | |
* @param platform {string} The desired platform. |
@@ -56,6 +77,10 @@ class Tldr { | |||
}); | |||
} | |||
|
|||
/** | |||
* Print a random page. |
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.
* Print a random page. | |
* Print a random page example. |
@@ -16,10 +16,19 @@ class Cache { | |||
this.cacheFolder = path.join(config.cache, 'cache'); | |||
} | |||
|
|||
/** | |||
* Fetch stats from the cache folder. |
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.
* Fetch stats from the cache folder. | |
* Fetch stats from the cache folder for getting its last modified time (mtime). |
// There is no need to re-read the index file again. | ||
/** | ||
* Check if a page is in the index. | ||
* @returns {boolean} A boolean that indicates if the page is present. |
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.
* @returns {boolean} A boolean that indicates if the page is present. | |
* @returns {boolean} The presence of the page in the index. |
clear() { | ||
return fs.remove(this.cacheFolder); | ||
} | ||
|
||
/** | ||
* Update the cache folder and returns the English entries. |
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.
* Update the cache folder and returns the English entries. | |
* Update the cache folder using a temporary directory, update the index and return it. |
@@ -21,6 +21,11 @@ class Tldr { | |||
this.cache = new Cache(this.config); | |||
} | |||
|
|||
/** | |||
* Print pages for a given platform.. | |||
* @param singleColumn {boolean} A boolean to print one command per line. |
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.
* @param singleColumn {boolean} A boolean to print one command per line. | |
* @param singleColumn {boolean} Print one command per line. |
@@ -29,17 +34,33 @@ class Tldr { | |||
}); | |||
} | |||
|
|||
/** | |||
* Print all pages in the cache. |
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.
* Print all pages in the cache. | |
* Print the name of all pages in the index. |
@@ -108,6 +155,12 @@ class Tldr { | |||
}); | |||
} | |||
|
|||
/** | |||
* Print all pages. |
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.
* Print all pages. | |
* Print the name of all pages. |
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.
What is the difference between
Promise<any>
andPromise<unknown>
?
See https://stackoverflow.com/questions/51439843/unknown-vs-any. In summary:
More verbosely, unknown is I don't know (yet), thus I have to figure it out, any is I don't care, thus I don't care
I think there are too many any
s/unknown
s here, but we can change them later if we need.
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.
I still see my comments not addressed yet. Feel free to request a review once that's done. Thanks.
IMO we can take over this PR, since it was opened 2 years ago with no response since then. |
Description
Please explain the changes you made here.
Checklist
Please review this checklist before submitting a pull request.
npm run test:all
)