Skip to content

Commit 4487d4a

Browse files
committed
fix: make files in src/ jshint: eqeqeq compatible
Add exceptions to the rule in input, ngAria, and parse. For input and ngAria, the exception is to prevent a breaking change in the radio directive. A test for the input behavior has been added. For parse, the exception covers non-strict expression comparison.
1 parent 874c0fd commit 4487d4a

36 files changed

+127
-106
lines changed

src/Angular.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function isArrayLike(obj) {
195195
// NodeList objects (with `item` method) and
196196
// other objects with suitable length characteristics are array-like
197197
return isNumber(length) &&
198-
(length >= 0 && ((length - 1) in obj || obj instanceof Array) || typeof obj.item == 'function');
198+
(length >= 0 && ((length - 1) in obj || obj instanceof Array) || typeof obj.item === 'function');
199199

200200
}
201201

@@ -241,7 +241,9 @@ function forEach(obj, iterator, context) {
241241
for (key in obj) {
242242
// Need to check if hasOwnProperty exists,
243243
// as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
244-
if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
244+
if (key !== 'prototype' && key !== 'length' && key !== 'name' &&
245+
(!obj.hasOwnProperty || obj.hasOwnProperty(key))
246+
) {
245247
iterator.call(context, obj[key], key, obj);
246248
}
247249
}
@@ -718,7 +720,7 @@ function nodeName_(element) {
718720
}
719721

720722
function includes(array, obj) {
721-
return Array.prototype.indexOf.call(array, obj) != -1;
723+
return Array.prototype.indexOf.call(array, obj) !== -1;
722724
}
723725

724726
function arrayRemove(array, value) {
@@ -984,10 +986,10 @@ function equals(o1, o2) {
984986
if (o1 === null || o2 === null) return false;
985987
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
986988
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
987-
if (t1 == t2 && t1 == 'object') {
989+
if (t1 === t2 && t1 === 'object') {
988990
if (isArray(o1)) {
989991
if (!isArray(o2)) return false;
990-
if ((length = o1.length) == o2.length) {
992+
if ((length = o1.length) === o2.length) {
991993
for (key = 0; key < length; key++) {
992994
if (!equals(o1[key], o2[key])) return false;
993995
}
@@ -998,7 +1000,7 @@ function equals(o1, o2) {
9981000
return equals(o1.getTime(), o2.getTime());
9991001
} else if (isRegExp(o1)) {
10001002
if (!isRegExp(o2)) return false;
1001-
return o1.toString() == o2.toString();
1003+
return o1.toString() === o2.toString();
10021004
} else {
10031005
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
10041006
isArray(o2) || isDate(o2) || isRegExp(o2)) return false;

src/apis.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function hashKey(obj, nextUidFn) {
2424
}
2525

2626
var objType = typeof obj;
27-
if (objType == 'function' || (objType == 'object' && obj !== null)) {
27+
if (objType === 'function' || (objType === 'object' && obj !== null)) {
2828
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
2929
} else {
3030
key = objType + ':' + obj;

src/auto/injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ function createInjector(modulesToLoad, strictDi) {
774774
if (isArray(module)) {
775775
module = module[module.length - 1];
776776
}
777-
if (e.message && e.stack && e.stack.indexOf(e.message) == -1) {
777+
if (e.message && e.stack && e.stack.indexOf(e.message) === -1) {
778778
// Safari & FF's stack traces don't contain error.message content
779779
// unlike those of Chrome and IE
780780
// So if stack doesn't contain message, we create a new string that contains both.

src/jqLite.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function JQLite(element) {
277277
argIsString = true;
278278
}
279279
if (!(this instanceof JQLite)) {
280-
if (argIsString && element.charAt(0) != '<') {
280+
if (argIsString && element.charAt(0) !== '<') {
281281
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
282282
}
283283
return new JQLite(element);
@@ -472,7 +472,7 @@ function jqLiteController(element, name) {
472472
function jqLiteInheritedData(element, name, value) {
473473
// if element is the document object work with the html element instead
474474
// this makes $(document).scope() possible
475-
if (element.nodeType == NODE_TYPE_DOCUMENT) {
475+
if (element.nodeType === NODE_TYPE_DOCUMENT) {
476476
element = element.documentElement;
477477
}
478478
var names = isArray(name) ? name : [name];
@@ -724,7 +724,7 @@ forEach({
724724
// in a way that survives minification.
725725
// jqLiteEmpty takes no arguments but is a setter.
726726
if (fn !== jqLiteEmpty &&
727-
(isUndefined((fn.length == 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2))) {
727+
(isUndefined((fn.length === 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2))) {
728728
if (isObject(arg1)) {
729729

730730
// we are a write, but the object properties are the key/values

src/ng/cacheFactory.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ function $CacheFactoryProvider() {
216216

217217
if (!lruEntry) return;
218218

219-
if (lruEntry == freshEnd) freshEnd = lruEntry.p;
220-
if (lruEntry == staleEnd) staleEnd = lruEntry.n;
219+
if (lruEntry === freshEnd) freshEnd = lruEntry.p;
220+
if (lruEntry === staleEnd) staleEnd = lruEntry.n;
221221
link(lruEntry.n,lruEntry.p);
222222

223223
delete lruHash[key];
@@ -289,10 +289,10 @@ function $CacheFactoryProvider() {
289289
* makes the `entry` the freshEnd of the LRU linked list
290290
*/
291291
function refresh(entry) {
292-
if (entry != freshEnd) {
292+
if (entry !== freshEnd) {
293293
if (!staleEnd) {
294294
staleEnd = entry;
295-
} else if (staleEnd == entry) {
295+
} else if (staleEnd === entry) {
296296
staleEnd = entry.n;
297297
}
298298

@@ -308,7 +308,7 @@ function $CacheFactoryProvider() {
308308
* bidirectionally links two entries of the LRU linked list
309309
*/
310310
function link(nextEntry, prevEntry) {
311-
if (nextEntry != prevEntry) {
311+
if (nextEntry !== prevEntry) {
312312
if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify
313313
if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify
314314
}

src/ng/compile.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15511551

15521552
var startSymbol = $interpolate.startSymbol(),
15531553
endSymbol = $interpolate.endSymbol(),
1554-
denormalizeTemplate = (startSymbol == '{{' && endSymbol == '}}')
1554+
denormalizeTemplate = (startSymbol === '{{' && endSymbol === '}}')
15551555
? identity
15561556
: function denormalizeTemplate(template) {
15571557
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
@@ -1946,7 +1946,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19461946
"Unterminated attribute, found '{0}' but no matching '{1}' found.",
19471947
attrStart, attrEnd);
19481948
}
1949-
if (node.nodeType == NODE_TYPE_ELEMENT) {
1949+
if (node.nodeType === NODE_TYPE_ELEMENT) {
19501950
if (node.hasAttribute(attrStart)) depth++;
19511951
if (node.hasAttribute(attrEnd)) depth--;
19521952
}
@@ -2132,7 +2132,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
21322132
nonTlbTranscludeDirective = directive;
21332133
}
21342134

2135-
if (directiveValue == 'element') {
2135+
if (directiveValue === 'element') {
21362136
hasElementTranscludeDirective = true;
21372137
terminalPriority = directive.priority;
21382138
$template = $compileNode;
@@ -2250,7 +2250,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22502250
}
22512251
compileNode = $template[0];
22522252

2253-
if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
2253+
if ($template.length !== 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
22542254
throw $compileMinErr('tplrt',
22552255
"Template for directive '{0}' must have exactly one root element. {1}",
22562256
directiveName, '');
@@ -2635,7 +2635,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26352635
try {
26362636
directive = directives[i];
26372637
if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
2638-
directive.restrict.indexOf(location) != -1) {
2638+
directive.restrict.indexOf(location) !== -1) {
26392639
if (startAttrName) {
26402640
directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
26412641
}
@@ -2692,7 +2692,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26922692

26932693
// reapply the old attributes to the new element
26942694
forEach(dst, function(value, key) {
2695-
if (key.charAt(0) != '$') {
2695+
if (key.charAt(0) !== '$') {
26962696
if (src[key] && src[key] !== value) {
26972697
value += (key === 'style' ? ';' : ' ') + src[key];
26982698
}
@@ -2702,16 +2702,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27022702

27032703
// copy the new attributes on the old attrs object
27042704
forEach(src, function(value, key) {
2705-
if (key == 'class') {
2705+
if (key === 'class') {
27062706
safeAddClass($element, value);
27072707
dst['class'] = (dst['class'] ? dst['class'] + ' ' : '') + value;
2708-
} else if (key == 'style') {
2708+
} else if (key === 'style') {
27092709
$element.attr('style', $element.attr('style') + ';' + value);
27102710
dst['style'] = (dst['style'] ? dst['style'] + ';' : '') + value;
27112711
// `dst` will never contain hasOwnProperty as DOM parser won't let it.
27122712
// You will get an "InvalidCharacterError: DOM Exception 5" error if you
27132713
// have an attribute like "has-own-property" or "data-has-own-property", etc.
2714-
} else if (key.charAt(0) != '$' && !dst.hasOwnProperty(key)) {
2714+
} else if (key.charAt(0) !== '$' && !dst.hasOwnProperty(key)) {
27152715
dst[key] = value;
27162716
dstAttr[key] = srcAttr[key];
27172717
}
@@ -2750,7 +2750,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27502750
}
27512751
compileNode = $template[0];
27522752

2753-
if ($template.length != 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
2753+
if ($template.length !== 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
27542754
throw $compileMinErr('tplrt',
27552755
"Template for directive '{0}' must have exactly one root element. {1}",
27562756
origAsyncDirective.name, templateUrl);
@@ -2778,7 +2778,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
27782778
childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns,
27792779
previousCompileContext);
27802780
forEach($rootElement, function(node, i) {
2781-
if (node == compileNode) {
2781+
if (node === compileNode) {
27822782
$rootElement[i] = $compileNode[0];
27832783
}
27842784
});
@@ -2903,15 +2903,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
29032903

29042904

29052905
function getTrustedContext(node, attrNormalizedName) {
2906-
if (attrNormalizedName == "srcdoc") {
2906+
if (attrNormalizedName === "srcdoc") {
29072907
return $sce.HTML;
29082908
}
29092909
var tag = nodeName_(node);
29102910
// maction[xlink:href] can source SVG. It's not limited to <maction>.
2911-
if (attrNormalizedName == "xlinkHref" ||
2912-
(tag == "form" && attrNormalizedName == "action") ||
2913-
(tag != "img" && (attrNormalizedName == "src" ||
2914-
attrNormalizedName == "ngSrc"))) {
2911+
if (attrNormalizedName === "xlinkHref" ||
2912+
(tag === "form" && attrNormalizedName === "action") ||
2913+
(tag !== "img" && (attrNormalizedName === "src" ||
2914+
attrNormalizedName === "ngSrc"))) {
29152915
return $sce.RESOURCE_URL;
29162916
}
29172917
}
@@ -2974,7 +2974,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
29742974
//skip animations when the first digest occurs (when
29752975
//both the new and the old values are the same) since
29762976
//the CSS classes are the non-interpolated values
2977-
if (name === 'class' && newValue != oldValue) {
2977+
if (name === 'class' && newValue !== oldValue) {
29782978
attr.$updateClass(newValue, oldValue);
29792979
} else {
29802980
attr.$set(name, newValue);
@@ -3005,7 +3005,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
30053005

30063006
if ($rootElement) {
30073007
for (i = 0, ii = $rootElement.length; i < ii; i++) {
3008-
if ($rootElement[i] == firstElementToRemove) {
3008+
if ($rootElement[i] === firstElementToRemove) {
30093009
$rootElement[i++] = newNode;
30103010
for (var j = i, j2 = j + removeCount - 1,
30113011
jj = $rootElement.length;
@@ -3308,7 +3308,7 @@ function tokenDifference(str1, str2) {
33083308
for (var i = 0; i < tokens1.length; i++) {
33093309
var token = tokens1[i];
33103310
for (var j = 0; j < tokens2.length; j++) {
3311-
if (token == tokens2[j]) continue outer;
3311+
if (token === tokens2[j]) continue outer;
33123312
}
33133313
values += (values.length > 0 ? ' ' : '') + token;
33143314
}

src/ng/directive/attrs.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ var ngAttributeAliasDirectives = {};
332332
// boolean attrs are evaluated
333333
forEach(BOOLEAN_ATTR, function(propName, attrName) {
334334
// binding to multiple is not supported
335-
if (propName == "multiple") return;
335+
if (propName === "multiple") return;
336336

337337
function defaultLinkFn(scope, element, attr) {
338338
scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
@@ -369,7 +369,7 @@ forEach(ALIASED_ATTR, function(htmlAttr, ngAttr) {
369369
link: function(scope, element, attr) {
370370
//special case ngPattern when a literal regular expression value
371371
//is used as the expression (this way we don't have to watch anything).
372-
if (ngAttr === "ngPattern" && attr.ngPattern.charAt(0) == "/") {
372+
if (ngAttr === "ngPattern" && attr.ngPattern.charAt(0) === "/") {
373373
var match = attr.ngPattern.match(REGEX_STRING_REGEXP);
374374
if (match) {
375375
attr.$set("ngPattern", new RegExp(match[1], match[2]));

src/ng/directive/input.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ function createDateParser(regexp, mapping) {
12591259
// When a date is JSON'ified to wraps itself inside of an extra
12601260
// set of double quotes. This makes the date parsing code unable
12611261
// to match the date string and parse it as a date.
1262-
if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') {
1262+
if (iso.charAt(0) === '"' && iso.charAt(iso.length - 1) === '"') {
12631263
iso = iso.substring(1, iso.length - 1);
12641264
}
12651265
if (ISO_DATE_REGEXP.test(iso)) {
@@ -1476,6 +1476,8 @@ function radioInputType(scope, element, attr, ctrl) {
14761476

14771477
ctrl.$render = function() {
14781478
var value = attr.value;
1479+
// Strict comparison would cause a BC
1480+
/* jshint eqeqeq:false */
14791481
element[0].checked = (value == ctrl.$viewValue);
14801482
};
14811483

src/ng/directive/ngClass.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function classDirective(name, selector) {
9090
for (var i = 0; i < tokens1.length; i++) {
9191
var token = tokens1[i];
9292
for (var j = 0; j < tokens2.length; j++) {
93-
if (token == tokens2[j]) continue outer;
93+
if (token === tokens2[j]) continue outer;
9494
}
9595
values.push(token);
9696
}

src/ng/directive/ngRepeat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
519519
nextNode = nextNode.nextSibling;
520520
} while (nextNode && nextNode[NG_REMOVED]);
521521

522-
if (getBlockStart(block) != nextNode) {
522+
if (getBlockStart(block) !== nextNode) {
523523
// existing item which got moved
524524
$animate.move(getBlockNodes(block.clone), null, previousNode);
525525
}

src/ng/directive/script.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var scriptDirective = ['$templateCache', function($templateCache) {
3838
restrict: 'E',
3939
terminal: true,
4040
compile: function(element, attr) {
41-
if (attr.type == 'text/ng-template') {
41+
if (attr.type === 'text/ng-template') {
4242
var templateUrl = attr.id,
4343
text = element[0].text;
4444

src/ng/filter/filters.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,16 @@ function parse(numStr) {
175175
}
176176

177177
// Count the number of leading zeros.
178-
for (i = 0; numStr.charAt(i) == ZERO_CHAR; i++) {/* jshint noempty: false */}
178+
for (i = 0; numStr.charAt(i) === ZERO_CHAR; i++) {/* jshint noempty: false */}
179179

180-
if (i == (zeros = numStr.length)) {
180+
if (i === (zeros = numStr.length)) {
181181
// The digits are all zero.
182182
digits = [0];
183183
numberOfIntegerDigits = 1;
184184
} else {
185185
// Count the number of trailing zeros
186186
zeros--;
187-
while (numStr.charAt(zeros) == ZERO_CHAR) zeros--;
187+
while (numStr.charAt(zeros) === ZERO_CHAR) zeros--;
188188

189189
// Trailing zeros are insignificant so ignore them
190190
numberOfIntegerDigits -= i;
@@ -376,7 +376,7 @@ function dateGetter(name, size, offset, trim, negWrap) {
376376
if (offset > 0 || value > -offset) {
377377
value += offset;
378378
}
379-
if (value === 0 && offset == -12) value = 12;
379+
if (value === 0 && offset === -12) value = 12;
380380
return padNumber(value, size, trim, negWrap);
381381
};
382382
}

src/ng/filter/orderBy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ function orderByFilter($parse) {
248248
if (isFunction(predicate)) {
249249
get = predicate;
250250
} else if (isString(predicate)) {
251-
if ((predicate.charAt(0) == '+' || predicate.charAt(0) == '-')) {
252-
descending = predicate.charAt(0) == '-' ? -1 : 1;
251+
if ((predicate.charAt(0) === '+' || predicate.charAt(0) === '-')) {
252+
descending = predicate.charAt(0) === '-' ? -1 : 1;
253253
predicate = predicate.substring(1);
254254
}
255255
if (predicate !== '') {

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ function $HttpProvider() {
13231323

13241324
function buildUrl(url, serializedParams) {
13251325
if (serializedParams.length > 0) {
1326-
url += ((url.indexOf('?') == -1) ? '?' : '&') + serializedParams;
1326+
url += ((url.indexOf('?') === -1) ? '?' : '&') + serializedParams;
13271327
}
13281328
return url;
13291329
}

src/ng/httpBackend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
5858
$browser.$$incOutstandingRequestCount();
5959
url = url || $browser.url();
6060

61-
if (lowercase(method) == 'jsonp') {
61+
if (lowercase(method) === 'jsonp') {
6262
var callbackId = '_' + (callbacks.counter++).toString(36);
6363
callbacks[callbackId] = function(data) {
6464
callbacks[callbackId].data = data;
@@ -95,7 +95,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
9595
// Occurs when accessing file resources or on Android 4.1 stock browser
9696
// while retrieving files from application cache.
9797
if (status === 0) {
98-
status = response ? 200 : urlResolve(url).protocol == 'file' ? 404 : 0;
98+
status = response ? 200 : urlResolve(url).protocol === 'file' ? 404 : 0;
9999
}
100100

101101
completeRequest(callback,

0 commit comments

Comments
 (0)