Skip to content

Commit 10bee82

Browse files
committed
More linting (equality vs identity comparisons)
1 parent aa39da6 commit 10bee82

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"jquery": true,
33
"browser": true,
44

5-
//"eqeqeq": true,
5+
"eqeqeq": true,
66
"freeze": true,
77
//"indent": 4, // when we move to spaces
88
"latedef": true,

js/bootstrap-datepicker.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@
265265
_applyEvents: function(evs){
266266
for (var i=0, el, ch, ev; i<evs.length; i++){
267267
el = evs[i][0];
268-
if (evs[i].length == 2){
268+
if (evs[i].length === 2){
269269
ch = undefined;
270270
ev = evs[i][1];
271271
}
272-
else if (evs[i].length == 3){
272+
else if (evs[i].length === 3){
273273
ch = evs[i][1];
274274
ev = evs[i][2];
275275
}
@@ -279,11 +279,11 @@
279279
_unapplyEvents: function(evs){
280280
for (var i=0, el, ev, ch; i<evs.length; i++){
281281
el = evs[i][0];
282-
if (evs[i].length == 2){
282+
if (evs[i].length === 2){
283283
ch = undefined;
284284
ev = evs[i][1];
285285
}
286-
else if (evs[i].length == 3){
286+
else if (evs[i].length === 3){
287287
ch = evs[i][1];
288288
ev = evs[i][2];
289289
}
@@ -393,7 +393,7 @@
393393
ix = this.dates.length - 1;
394394
format = this.o.format;
395395
}
396-
else if (typeof ix == 'string'){
396+
else if (typeof ix === 'string'){
397397
format = ix;
398398
ix = this.dates.length - 1;
399399
}
@@ -537,7 +537,7 @@
537537
scrollTop = $window.scrollTop();
538538

539539
var zIndex = parseInt(this.element.parents().filter(function() {
540-
return $(this).css('z-index') != 'auto';
540+
return $(this).css('z-index') !== 'auto';
541541
}).first().css('z-index'))+10;
542542
var offset = this.component ? this.component.parent().offset() : this.element.offset();
543543
var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
@@ -686,18 +686,18 @@
686686
year = this.viewDate.getUTCFullYear(),
687687
month = this.viewDate.getUTCMonth(),
688688
today = new Date();
689-
if (date.getUTCFullYear() < year || (date.getUTCFullYear() == year && date.getUTCMonth() < month)) {
689+
if (date.getUTCFullYear() < year || (date.getUTCFullYear() === year && date.getUTCMonth() < month)) {
690690
cls.push('old');
691-
} else if (date.getUTCFullYear() > year || (date.getUTCFullYear() == year && date.getUTCMonth() > month)) {
691+
} else if (date.getUTCFullYear() > year || (date.getUTCFullYear() === year && date.getUTCMonth() > month)) {
692692
cls.push('new');
693693
}
694694
if (this.focusDate && date.valueOf() === this.focusDate.valueOf())
695695
cls.push('focused');
696696
// Compare internal UTC date with local today, not UTC today
697697
if (this.o.todayHighlight &&
698-
date.getUTCFullYear() == today.getFullYear() &&
699-
date.getUTCMonth() == today.getMonth() &&
700-
date.getUTCDate() == today.getDate()) {
698+
date.getUTCFullYear() === today.getFullYear() &&
699+
date.getUTCMonth() === today.getMonth() &&
700+
date.getUTCDate() === today.getDate()) {
701701
cls.push('today');
702702
}
703703
if (this.dates.contains(date) !== -1)
@@ -710,7 +710,7 @@
710710
if (date > this.range[0] && date < this.range[this.range.length-1]){
711711
cls.push('range');
712712
}
713-
if ($.inArray(date.valueOf(), this.range) != -1){
713+
if ($.inArray(date.valueOf(), this.range) !== -1){
714714
cls.push('selected');
715715
}
716716
}
@@ -746,7 +746,7 @@
746746
var html = [];
747747
var clsName;
748748
while(prevMonth.valueOf() < nextMonth) {
749-
if (prevMonth.getUTCDay() == this.o.weekStart) {
749+
if (prevMonth.getUTCDay() === this.o.weekStart) {
750750
html.push('<tr>');
751751
if(this.o.calendarWeeks){
752752
// ISO 8601: First week contains first thursday.
@@ -785,7 +785,7 @@
785785

786786
clsName = $.unique(clsName);
787787
html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
788-
if (prevMonth.getUTCDay() == this.o.weekEnd) {
788+
if (prevMonth.getUTCDay() === this.o.weekEnd) {
789789
html.push('</tr>');
790790
}
791791
prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
@@ -799,17 +799,17 @@
799799
.find('span').removeClass('active');
800800

801801
$.each(this.dates, function(i, d){
802-
if (d.getUTCFullYear() == year)
802+
if (d.getUTCFullYear() === year)
803803
months.eq(d.getUTCMonth()).addClass('active');
804804
});
805805

806806
if (year < startYear || year > endYear) {
807807
months.addClass('disabled');
808808
}
809-
if (year == startYear) {
809+
if (year === startYear) {
810810
months.slice(0, startMonth).addClass('disabled');
811811
}
812-
if (year == endYear) {
812+
if (year === endYear) {
813813
months.slice(endMonth+1).addClass('disabled');
814814
}
815815

@@ -878,7 +878,7 @@
878878
e.preventDefault();
879879
var target = $(e.target).closest('span, td, th'),
880880
year, month, day;
881-
if (target.length == 1) {
881+
if (target.length === 1) {
882882
switch(target[0].nodeName.toLowerCase()) {
883883
case 'th':
884884
switch(target[0].className) {
@@ -887,7 +887,7 @@
887887
break;
888888
case 'prev':
889889
case 'next':
890-
var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
890+
var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1);
891891
switch(this.viewMode){
892892
case 0:
893893
this.viewDate = this.moveMonth(this.viewDate, dir);
@@ -907,7 +907,7 @@
907907
date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
908908

909909
this.showMode(-2);
910-
var which = this.o.todayBtn == 'linked' ? null : 'view';
910+
var which = this.o.todayBtn === 'linked' ? null : 'view';
911911
this._setDate(date, which);
912912
break;
913913
case 'clear':
@@ -964,7 +964,7 @@
964964
month -= 1;
965965
}
966966
} else if (target.is('.new')) {
967-
if (month == 11) {
967+
if (month === 11) {
968968
month = 0;
969969
year += 1;
970970
} else {
@@ -993,15 +993,15 @@
993993
else{
994994
this.dates.push(date);
995995
}
996-
if (typeof this.o.multidate == 'number')
996+
if (typeof this.o.multidate === 'number')
997997
while (this.dates.length > this.o.multidate)
998998
this.dates.remove(0);
999999
},
10001000

10011001
_setDate: function(date, which){
1002-
if (!which || which == 'date')
1002+
if (!which || which === 'date')
10031003
this._toggle_multidate(date && new Date(date));
1004-
if (!which || which == 'view')
1004+
if (!which || which === 'view')
10051005
this.viewDate = date && new Date(date);
10061006

10071007
this.fill();
@@ -1016,7 +1016,7 @@
10161016
if (element) {
10171017
element.change();
10181018
}
1019-
if (this.o.autoclose && (!which || which == 'date')) {
1019+
if (this.o.autoclose && (!which || which === 'date')) {
10201020
this.hide();
10211021
}
10221022
},
@@ -1030,14 +1030,14 @@
10301030
mag = Math.abs(dir),
10311031
new_month, test;
10321032
dir = dir > 0 ? 1 : -1;
1033-
if (mag == 1){
1034-
test = dir == -1
1033+
if (mag === 1){
1034+
test = dir === -1
10351035
// If going back one month, make sure month is not current month
10361036
// (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
1037-
? function(){ return new_date.getUTCMonth() == month; }
1037+
? function(){ return new_date.getUTCMonth() === month; }
10381038
// If going forward one month, make sure month is as expected
10391039
// (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
1040-
: function(){ return new_date.getUTCMonth() != new_month; };
1040+
: function(){ return new_date.getUTCMonth() !== new_month; };
10411041
new_month = month + dir;
10421042
new_date.setUTCMonth(new_month);
10431043
// Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
@@ -1051,7 +1051,7 @@
10511051
// ...then reset the day, keeping it in the new month
10521052
new_month = new_date.getUTCMonth();
10531053
new_date.setUTCDate(day);
1054-
test = function(){ return new_month != new_date.getUTCMonth(); };
1054+
test = function(){ return new_month !== new_date.getUTCMonth(); };
10551055
}
10561056
// Common date-resetting loop -- if date is beyond end of month, make it
10571057
// end of month
@@ -1072,7 +1072,7 @@
10721072

10731073
keydown: function(e){
10741074
if (this.picker.is(':not(:visible)')){
1075-
if (e.keyCode == 27) // allow escape to hide and re-show picker
1075+
if (e.keyCode === 27) // allow escape to hide and re-show picker
10761076
this.show();
10771077
return;
10781078
}
@@ -1093,7 +1093,7 @@
10931093
case 37: // left
10941094
case 39: // right
10951095
if (!this.o.keyboardNavigation) break;
1096-
dir = e.keyCode == 37 ? -1 : 1;
1096+
dir = e.keyCode === 37 ? -1 : 1;
10971097
if (e.ctrlKey){
10981098
newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
10991099
newViewDate = this.moveYear(focusDate, dir);
@@ -1118,7 +1118,7 @@
11181118
case 38: // up
11191119
case 40: // down
11201120
if (!this.o.keyboardNavigation) break;
1121-
dir = e.keyCode == 38 ? -1 : 1;
1121+
dir = e.keyCode === 38 ? -1 : 1;
11221122
if (e.ctrlKey){
11231123
newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
11241124
newViewDate = this.moveYear(focusDate, dir);
@@ -1230,7 +1230,8 @@
12301230
new_date = dp.getUTCDate(),
12311231
i = $.inArray(e.target, this.inputs),
12321232
l = this.inputs.length;
1233-
if (i == -1) return;
1233+
if (i === -1)
1234+
return;
12341235

12351236
$.each(this.pickers, function(i, p){
12361237
if (!p.getUTCDate())
@@ -1302,7 +1303,7 @@
13021303
this.each(function () {
13031304
var $this = $(this),
13041305
data = $this.data('datepicker'),
1305-
options = typeof option == 'object' && option;
1306+
options = typeof option === 'object' && option;
13061307
if (!data) {
13071308
var elopts = opts_from_el(this, 'date'),
13081309
// Preliminary otions
@@ -1320,7 +1321,7 @@
13201321
$this.data('datepicker', (data = new Datepicker(this, opts)));
13211322
}
13221323
}
1323-
if (typeof option == 'string' && typeof data[option] == 'function') {
1324+
if (typeof option === 'string' && typeof data[option] === 'function') {
13241325
internal_return = data[option].apply(data, args);
13251326
if (internal_return !== undefined)
13261327
return false;
@@ -1452,7 +1453,7 @@
14521453
while (v<0) v += 12;
14531454
v %= 12;
14541455
d.setUTCMonth(v);
1455-
while (d.getUTCMonth() != v)
1456+
while (d.getUTCMonth() !== v)
14561457
d.setUTCDate(d.getUTCDate()-1);
14571458
return d;
14581459
},
@@ -1464,7 +1465,7 @@
14641465
date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
14651466
var fparts = format.parts.slice();
14661467
// Remove noop parts
1467-
if (parts.length != fparts.length) {
1468+
if (parts.length !== fparts.length) {
14681469
fparts = $(fparts).filter(function(i,p){
14691470
return $.inArray(p, setters_order) !== -1;
14701471
}).toArray();
@@ -1473,9 +1474,9 @@
14731474
function match_part(){
14741475
var m = this.slice(0, parts[i].length),
14751476
p = parts[i].slice(0, m.length);
1476-
return m == p;
1477+
return m === p;
14771478
}
1478-
if (parts.length == fparts.length) {
1479+
if (parts.length === fparts.length) {
14791480
var cnt;
14801481
for (i=0, cnt = fparts.length; i < cnt; i++) {
14811482
val = parseInt(parts[i], 10);

0 commit comments

Comments
 (0)