-
Notifications
You must be signed in to change notification settings - Fork 3
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
JavaScript / jQuery code needs cleaning up #672
Comments
Can we make this a little bit more specific? Is there some linting that we can use so it is clear what "clean" and "not clean" means? If we can not check if an issue has been solved, it will just hang here forever... |
What's wrong with this, apart from somewhat passé use of (The |
@richardhadden Are you saying all the equality checks were purposefully written that way? I doubt that. When I see loose checks instead of strict ones in JS code which doesn't follow other conventions, that, to me, is an(other) indicator it was likely written by someone who didn't know better. And I wasn't taking issue with verifying if the cookie exists, I was commenting on its implementation. These things accumulate. The |
Relevant docs + choice quotes: Equality comparisons and sameness:
typeof operator and undefined:
|
I was about to mention the (absence of) strict equality checking :)
Either way, we don't need to check whether it has a literal type of "undefined" — just whether it's there (otherwise we should also check it isn't null either). I'm tempted to argue we don't need the second part, as empty string is also falsy! |
Fair enough. We both interpreted its intent to be to check for And yeah, looks like it never does not exist in major browsers. I didn't even look at what the cookie does, so not sure if we even still need that check at all. The last cookie-related code I encountered was for the now-removed toggle between view/edit mode for entities, which is the kind of setting I'd use |
Just for context: the code is apparently coming from this stackoverflow post: https://stackoverflow.com/a/23350233 It is used in the relations javascript to set the CSRF token for ajax form of the relations |
Interesting... especially considering content posted on SO is creative commons-licensed ("Subscriber Content" subsection). |
And the relevance of this in this context is..? |
Time spent discussing random copy-pasta feels like time wasted, to me. If the whole snippet was lifted from somewhere else, it's a bit pointless to discuss individual problems with it because the answer could simply be "laziness". Proper attribution would have made this clear right away. Additionally, my assumption now is this probably wasn't a one-off thing. Which makes unknown n% of the remaining code equally kind of pointless to discuss with regard to style etc. And also doesn't make me feel too confident about other things. |
q.e.d |
move all JS functions in dedicated *.js files in the static directory and run JS linters on these files:
|
all those tasks have been implemented |
Our code is full of incorrect JS comparisons and outdated variable declarations. This function declaration alone contains several instances of both.
Excerpt (example for both):
Should be:
That first check
if (document.cookie)
seems nonsensical either way, looks like Python transferred to JS. Unless that's special jQuery magic I'm not aware of (which is entirely possible, as I've never written any jQuery myself).The text was updated successfully, but these errors were encountered: