Describe the bug
This compliments work being done in #2470.
The *.js files inside app/javascript and app/assets/javascripts still have plenty of lint issues
To Reproduce
Steps to reproduce the behavior:
From the command line in the app/javascript folder, run eslint . --ext .js
From the command line in the app/assets/javascripts folder, run eslint . --ext .js
Expected behavior
There shouldn't be any lint issues.
Time to do some cleanup 馃槅

I would love to help out with this! I assume it will be much cleaner/smoother to fix a file, create a PR and then move on to the next, or should each fix be a commit in a PR?
Just create a PR and link it to this issue. Thanks for helping! 馃憦
Do you still need help with this? I'd love to take on some refactoring.
Hi @palledorous, please go ahead, I'm going to copy my recommendation from the other PR:
to make reviews easier and also curb the possibility of introducing bugs, is not to tackle too many files at the same time.
I went ahead and grouped the results of yarn run eslint app/assets/javascripts --ext ".js" and yarn run eslint app/javascript --ext ".js":
you're welcome to take on any of them!
I'll try to refactor initializeAllFollowButts.js
I have already made a PR for app/javascript/packs/notificationSubscriptionHandler.js! :)
Can we use arrow functions instead of function() ?
Yes you can use arrow functions and I believe the lint rules will prefer it in the case of anonymous functions.
Yeah, thanks
Do you still need help with this? I'd love to take on some refactoring.
@palledorous, I believe there is still work to be done in here. Just maybe sync up with the others in this thread to see which files they're working on.
Sounds good!
https://github.com/thepracticaldev/dev.to/blob/66faaccdd894a75887e6e3dfad30a3152e18a4fb/app/assets/javascripts/initializers/initNotifications.js#L48
This function maybe is missing an import from /app/assets/javascripts/utilities/checkUserLoggedIn.js?
This function maybe is missing an import from
/app/assets/javascripts/utilities/checkUserLoggedIn.js?
@netochaves, in the older part of the frontend code base, e.g. app/assets/javascripts/*, some functions are loaded in other files. There are no ES Modules in this part of the code base.
In this case, that function is defined here, https://github.com/thepracticaldev/dev.to/blob/66faaccdd894a75887e6e3dfad30a3152e18a4fb/app/assets/javascripts/utilities/checkUserLoggedIn.js. eslint is probably complaining about this function not being defined, so you will need to add checkUserLoggedIn to the eslint globals configuration, https://github.com/thepracticaldev/dev.to/blob/66faaccdd894a75887e6e3dfad30a3152e18a4fb/app/javascript/.eslintrc.js#L27
Do you mean here?
Yes, that is the file to add it to. I referenced the wrong eslint configuration file. 馃檭 More info on eslint globals here, https://eslint.org/docs/user-guide/configuring#specifying-globals
You can also declare globals inline in the file, since right now basically all functions in app/assets/javascripts are global, I'm not sure how worth it is to use the globals inside the eslint file :D
Thanks to everyone that has been working on this issue. Happy Hacktoberfest! 馃憦馃敟
@palledorous I've added your PR to the list up there!
I would like to take up /app/assets/javascripts/initializers/initializeArticleReactions.js
I want to take up initializeCommentDate.js, initializeCommentDropdown.js, initializeCommentPreview.js too next!
P.S. thanks rhymes for going through all PRs and marking all the files! :smiley: I did go through those but it seems I missed initializeArticleReactions in zach's PR, my bad.
@rhymes i would like to take up /app/assets/javascripts/utilities/sendFetch.js file
looks like sendFetch don't have any eslint error.
i will take up /app/assets/iinitializer/initializeCreditsPage.js
raised PR for it @rhymes . taking up initializeDashboardSort from app/assets/javascripts.
@sagarchoudhary96 if I run yarn eslint app/assets/javascripts/utilities/sendFetch.js I see an issue:
app/assets/javascripts/utilities/sendFetch.js
10:9 error Parsing error: Unexpected token ..
probably because the spread operator is not allowed in our configuration of eslintrc
@rhymes , yeah that the only one but i was reading about it, we will then need to make changes in eslintrc file for it.
@sagarchoudhary96 I would replace the spread operator TBH, changing the eslintrc means that we might introduce new lint errors (for example by bumping the version of JavaScript) in all files
also @rhymes , in app/assets/intializers/initializeDrawerSliders.js we are using function from other files for e.g initializeSwipeGestures() which is defined in initializeSwipeGestures.js file. so should i add import statements for those or leave them ?
@sagarchoudhary96 you can declare, inside initializeDrawerSliders.js those functions as global, with a statement like this at the top of the file: /* global initializeSwipeGestures */
I have a PR that fixes the issues with /app/assets/javascripts/lib/pulltorefresh.js coming up.
I would like to grab /app/assets/javascripts/initializers/initializeSettings.js
I would love to take /app/assets/javascripts/initializers/initializeBaseUserData.js!
@sagarchoudhary96 I would replace the spread operator TBH, changing the eslintrc means that we might introduce new lint errors (for example by bumping the version of JavaScript) in all files
I attempted to replace the spread operator by using the Object.assign approach. This resulted in a new lint error indicating that Object.assign is deprecated and should be replaced with the spread operator 馃槣. However I bumped the ecmaVersion in the app/assets/javascript directory and it did not result in any new lint errors.
@ludamillion I was looking into that locally myself earlier tonight and noticed the same thing. I think it may have even resolved several of the errors!
I would like to take on /bin/rails !
@dhanoz this issue is about JavaScript files :)
I would like to take /app/assets/javascripts/initializers/initializePodcastPlayback.js.
@3b3ziz sorry, we forgot to update the list, that file is already tackled on here https://github.com/thepracticaldev/dev.to/pull/4358
@nickytonline are you still working on pulltorefresh.js ?
No, I completely got sidetracked with other PRs and completely forgot about it. Feel free to grab it @3b3ziz.
@rhymes
Can I make a PR on /app/assets/javascripts/initializers/initializeTouchDevice.js?
I have fixed some of the lint errors in it!
@dhanoz This was already done at #4415
Can I take on to /app/assets/javascripts/initializers/initializeBaseUserData.js? @netochaves
Just updating the list of lint errors here as it's a lot smaller now.
app/assets/javascripts/initializers/initNotifications.js
49:5 error 'checkUserLoggedIn' is not defined no-undef
52:9 error 'instantClick' is not defined no-undef
53:7 error 'InstantClick' is not defined no-undef
55:9 error 'InstantClick' is not defined no-undef
72:11 error 'sendHapticMessage' is not defined no-undef
98:11 error 'butts' is already defined no-redeclare
99:16 error 'i' is already defined no-redeclare
100:13 error 'butt' is already defined no-redeclare
app/assets/javascripts/initializers/initializeAllFollowButts.js
84:5 error 'showModal' is not defined no-undef
132:3 error 'shouldNotFetch' is not defined no-undef
154:5 error 'showModal' is not defined no-undef
app/assets/javascripts/initializers/initializeSwipeGestures.js
3:3 error 'swipeState' is not defined no-undef
40:7 error 'swipeState' is not defined no-undef
41:5 error 'swipeState' is not defined no-undef
42:5 error 'slideSidebar' is not defined no-undef
45:5 error 'swipeState' is not defined no-undef
46:5 error 'slideSidebar' is not defined no-undef
53:7 error 'swipeState' is not defined no-undef
54:5 error 'swipeState' is not defined no-undef
55:5 error 'slideSidebar' is not defined no-undef
58:5 error 'swipeState' is not defined no-undef
59:5 error 'slideSidebar' is not defined no-undef
If you need to check this list you can run the following from your local, node_modules/.bin/eslint app/javascript/**/*.js.
I would like to pick up app/assets/javascripts/initializers/initializeSwipeGestures.js!
P.S. I think, in order to check the list, one needs to run: node_modules/.bin/eslint app/assets/javascripts/**/*.js 馃槄
All remaining lint issues in the frontend have been fixed. Now you will not be able to pass a build if you commit lint errors thanks to #9100 .
Most helpful comment
@dhanoz This was already done at #4415