Closed jjant closed 5 years ago
Thanks @jjant ! Very thorough code review, I learned a great deal.
After testing them, I merged almost all your changes as is for file-io.js
:+1:
As for the merge conflicts in main.js
, I kept many of them as they were in my branch, because most of the changes there were stylistic, and I had made some breaking changes of my own in the meantime. Didn't want to mess with it too much at this point...
Again, many thanks! :smile:
Description
I reviewed the
file-io.js
and its uses inmain.js
, no major issues were found, but several changes were made:There were a few uses of
sync
functions, these unnecessarily block the thread I've changed all of them to theirasync
variantsRemoved unused argument
legacyName
ofsaveLegacyFolderAs
var
uses, changing them forconst
orlet
as needed,var
has strange scope rules, so the newer keywords provide saner semantics. Also, most uses oflet
were changed forconst
. This makes it clearer which variables are mutated, surprisingly onlylet
1 remainedThe above change highlighted a possible problem in
saveSwapFolder
function, where the "notsavedBefore
" branch returnsundefined
. I've added a comment noting thisThere were some unnecessary uses of
promisify
forfs-extra
functions, those are already promisified by default (specifically,readFile
anddeleteFile
)I change documentation to use JSDoc, as well as adding JSDoc type annotations, while this by itself doesn't type-check expressions, it gives handy IDE hints (for example, it makes VSCode have a much more intelligent auto-complete). This would also help if you ever decide to use TypeScript, a note about this is that Promises are not typed on their error, so typings like
Promise<String, Error>
should be justPromise<String>
. I've decided to keep the former annotation for clarityLastly, I've streamlined styling, removing inconsistent spacing, adding semi-colons were missing, etc
On error handling
The most important things in these two files are that the
file-io.js
function all had redundant, unnecessarytry/catch
clauses that looked like this:This is effectively the same as just:
So I removed most of those. If you wanted to handle these errors, probably a better place to do it, is at the call site, I've added an example in
main.js
line 551.