-
-
Notifications
You must be signed in to change notification settings - Fork 78.5k
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
Improve JS style #13388
Improve JS style #13388
Conversation
I would recommend excluding the minified files and |
I don't mind rebasing for those only. |
@fat: I rebased the branch. |
cool |
@@ -562,7 +594,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re | |||
|
|||
var dimension = this.dimension() | |||
|
|||
/* jshint ignore:start */ |
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.
which rule needs us to do that?
in general things i like:
things i dont like:
|
I can keep the if/else in one liners but I still believe it's cleaner this way; the minifier will output the same code anyway. For |
So to summarize, things we still disagree:
|
yeah, im not sold on laxbreak and if/else |
for small expressions: for longer statements, i could see changing these to |
@cvrebert: can you check out this branch and update shrinkwrap? Otherwise Travis will fail since it will use JSHint 2.5.0. |
@XhmikosR Done. |
Thanks. BTW, what do you think of that last patch? Personally, I think it makes sense and reduces duplication. |
&& $href.length | ||
&& $href.is(':visible') | ||
&& [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null | ||
return ($href && |
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.
&&
on the next line looks so much better
things i still want:
|
@@ -1485,7 +1533,12 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re | |||
} | |||
} | |||
|
|||
self.tip().hasClass('in') ? self.leave(self) : self.enter(self) |
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.
self.tip().hasClass('in')
? self.leave(self)
: self.enter(self)
@fat: everyone needs to compromise a little bit. Sure, many changes are a matter of taste, but at least @cvrebert and I agree on these changes. I removed BTW, there's no enforcing option enabled for this. |
Rebased and skipped more stuff. I still want to have these changes eventually, but for now this should be ok in order to merge it. |
@@ -119,7 +121,9 @@ window.onload = function () { // wait for load in a dumb way because B-0 | |||
} | |||
if (data.vars) { | |||
for (var i in data.vars) { | |||
$('input[data-var="' + i + '"]').val(data.vars[i]) | |||
if (data.vars.hasOwnProperty(i)) { |
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.
do we need all these checks… who is extending the object prototype?
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.
In theory we do, in practice I doubt we'll ever have a problem. This branch was initially intended to make things stricter. Not just to make a tool happy, but to reduce the chances of making mistakes and having issues.
http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
In line with this, I'd rather we drop the hard rule of forcing |
I started this branch with the stuff I liked. Then I backed out many stuff in order to come to an agreement with @fat and I basically reverted half of the changes. I don't see this getting anywhere, unfortunately. |
Amazing work @XhmikosR 👍 |
I cannot disagree more strongly with the pro- |
I worry when I see I'd suggest you be a bit more thoughtful when making these blanket changes |
Nothing was done blindly.
|
@XhmikosR there's still some really good changes here, dont get too discouraged friend :) still open to having a convo about this stuff. Also, I think it's good going forward to have smaller pr's. that way the conversation can be more focused, etc :) |
Well, if you weren't absent @fat for so long, the branch would have been way smaller :P To summarize. As I have already told you privately, I totally respect the fact that you are the author of most of the JS in BS. I'm pretty sure you had, or even have, your reasons for your choices. What I wanted with this PR is to make things more consistent and less error prone. Plus, I'm not the only one who likes the changes I made which is something that led me to go through with this after all, even though I couldn't talk to you back then. Using JSHint isn't just something for fun; it really helps spotting issues like c93ac03 and 2a7f704. Before I rebased the branch the other day, I used curly braces everywhere, I got rid of the one line statements and a couple more things. Due to the fact that we are all people and we do mistakes, I personally prefer being stricter, as long as there's no (obvious) downside. I can break this PR in smaller patches; just tell me which stuff can go in, like now, and I'll rebase the branch. |
@XhmikosR I apologize then. I had assumed you were following JSHint's suggestions |
@@ -57,7 +56,7 @@ | |||
return ($href | |||
&& $href.length | |||
&& $href.is(':visible') | |||
&& [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null | |||
&& [[$href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href]]) || null |
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.
this seems inconsistent with our spacing around {
, no?
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 haven't added spaces before [
and ]
. I can do it in another patch if everybody else agrees with this.
mm i would still prefer there to have been many little pr's to 1 big one. :)
Everything in this branch is awesome to me, except the If you want to back out the |
@fat: note that currently |
Be more consistent across the whole codebase. Also, make use of JSHint's 2.5.1 `extends` and `qunit` options. This way we set our basis options in js/.jshintrc and override the rest.
`slideIndex` is assigned to the same value a few lines above.
lgtm, thanks for suffering through this 😅 |
@fat: keep in mind I still would like to have the changes I reverted eventually. |
/CC @twbs/team