copy-and-watch
copy-and-watch copied to clipboard
Clean code, recursive directory copying and path normalization
I found this module to be broken after 2 years without updates, so I cleaned it up a bit and fixed some path normalization. Main changes are:
- Added path normalization (I'm 90% sure this fixes #3)
- Formatted & organized code
- Recursive directory copying
Also fixes #4 by mentioning the quote requirement in the readme.
Too many fixes.
npm run lint
show 71 errors
Whoops I completely forgot about the linter. I fixed almost all errors (most of them were the indentation), with just 2 remaining. These relate to the evil global variables, and it's a bit of a chicken-and-egg problem.
ESLint wants me to declare these variables before they are used. Fair game, it would be really stupid to bury globals like this. ESLint also wants me to define functions before they are used, again this makes a lot of sense. To solve this I can declare the globals on top, after that the functions that use them and lastly the actual code. Good? Wrong: ESLint wants me to declare these globals using const
because they are never reassigned.
This of course isn't possible, because I can't decalre a variable using const
without immediately initializing it. The only solution I see would be to split the acting code in half, the first part (which initializes the globals) before we define our functions, and the second part (which actual does stuff) afterwards.
I feel like this would actually make the code worse instead of cleaner, but of course if you really want to I could change it.
Still 2 lint errors
Because there is no reason for using arrow functions here, it just hurts readability. Having the actual function
keyword makes it very clear where the functions are instead of hiding them in variables.
-------- Oorspronkelijk bericht -------- Van: zont [email protected] Datum: 26-02-19 11:29 (GMT+01:00) Aan: zont/copy-and-watch [email protected] Cc: Ravi van Rooijen [email protected], Author [email protected] Onderwerp: Re: [zont/copy-and-watch] Clean code, recursive directory copying and path normalization (#5)
@zont commented on this pull request.
-const findTarget = from => { +/* FUNCTIONS */ +function findTarget(from) {
Why arrow functions converted to ES5 functions?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fzont%2Fcopy-and-watch%2Fpull%2F5%23pullrequestreview-207874541&data=02%7C01%7C%7C4b231cd7fc0c4a46f66908d69bd5486e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636867737668736355&sdata=at0vxTIzVsqCCcO7bOdqwGk2lQUPJf8R5tLtQA%2FFIKc%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAK8NwESOmE7f_yMMAox4QG1F4CcT_0Dmks5vRQyFgaJpZM4bQ5wg&data=02%7C01%7C%7C4b231cd7fc0c4a46f66908d69bd5486e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636867737668746359&sdata=uzwJIDyjoqzWYkHACuy%2Ft63%2FOV%2BRATPILPxKeSUaA6A%3D&reserved=0.
Please fix 2 lint errors
As I said earlier:
ESLint wants me to declare these variables before they are used. Fair game, it would be really stupid to bury globals like this. ESLint also wants me to define functions before they are used, again this makes a lot of sense. To solve this I can declare the globals on top, after that the functions that use them and lastly the actual code. Good? Wrong: ESLint wants me to declare these globals using
const
because they are never reassigned. This of course isn't possible, because I can't decalre a variable usingconst
without immediately initializing it. The only solution I see would be to split the acting code in half, the first part (which initializes the globals) before we define our functions, and the second part (which actual does stuff) afterwards. I feel like this would actually make the code worse instead of cleaner, but of course if you really want to I could change it.
There are 3 solutions:
- Splitting the 'acting' code (which would be really bad)
- Relaxing the lint settings
- Removing the globals (which would complicate some pieces of code)
I think relaxing the lint settings would be our best option, since splitting the 'acting' code hurts readability a lot.
Any update on this?