Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit accb22d

Browse files
hzoocaitp
authored andcommitted
style(*): enforce spaces after keywords, add spaces
Closes #9677
1 parent 1785251 commit accb22d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+271
-271
lines changed

.jscs.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"disallowKeywords": ["with"],
33
"disallowTrailingWhitespace": true,
44
"disallowSpaceAfterPrefixUnaryOperators": ["!"],
5-
"disallowSpaceBeforeBinaryOperators": [","]
5+
"disallowSpaceBeforeBinaryOperators": [","],
6+
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"]
67
}

.jscs.json.todo

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
{
77
"requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
8-
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
98
"requireSpaceAfterBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
109
"requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
1110
"disallowImplicitTypeConversion": ["string"],

src/Angular.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ function copy(source, destination, stackSource, stackDest) {
801801
});
802802
}
803803
for ( var key in source) {
804-
if(source.hasOwnProperty(key)) {
804+
if (source.hasOwnProperty(key)) {
805805
result = copy(source[key], null, stackSource, stackDest);
806806
if (isObject(source[key])) {
807807
stackSource.push(source[key]);
@@ -882,7 +882,7 @@ function equals(o1, o2) {
882882
if (isArray(o1)) {
883883
if (!isArray(o2)) return false;
884884
if ((length = o1.length) == o2.length) {
885-
for(key=0; key<length; key++) {
885+
for (key=0; key<length; key++) {
886886
if (!equals(o1[key], o2[key])) return false;
887887
}
888888
return true;
@@ -895,12 +895,12 @@ function equals(o1, o2) {
895895
} else {
896896
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return false;
897897
keySet = {};
898-
for(key in o1) {
898+
for (key in o1) {
899899
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
900900
if (!equals(o1[key], o2[key])) return false;
901901
keySet[key] = true;
902902
}
903-
for(key in o2) {
903+
for (key in o2) {
904904
if (!keySet.hasOwnProperty(key) &&
905905
key.charAt(0) !== '$' &&
906906
o2[key] !== undefined &&
@@ -1048,14 +1048,14 @@ function startingTag(element) {
10481048
// turns out IE does not let you set .html() on elements which
10491049
// are not allowed to have children. So we just ignore it.
10501050
element.empty();
1051-
} catch(e) {}
1051+
} catch (e) {}
10521052
var elemHtml = jqLite('<div>').append(element).html();
10531053
try {
10541054
return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
10551055
elemHtml.
10561056
match(/^(<[^>]+>)/)[1].
10571057
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
1058-
} catch(e) {
1058+
} catch (e) {
10591059
return lowercase(elemHtml);
10601060
}
10611061

@@ -1075,7 +1075,7 @@ function startingTag(element) {
10751075
function tryDecodeURIComponent(value) {
10761076
try {
10771077
return decodeURIComponent(value);
1078-
} catch(e) {
1078+
} catch (e) {
10791079
// Ignore any invalid uri component
10801080
}
10811081
}
@@ -1095,7 +1095,7 @@ function parseKeyValue(/**string*/keyValue) {
10951095
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
10961096
if (!hasOwnProperty.call(obj, key)) {
10971097
obj[key] = val;
1098-
} else if(isArray(obj[key])) {
1098+
} else if (isArray(obj[key])) {
10991099
obj[key].push(val);
11001100
} else {
11011101
obj[key] = [obj[key],val];

src/auto/injector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ function createInjector(modulesToLoad, strictDi) {
713713

714714
function runInvokeQueue(queue) {
715715
var i, ii;
716-
for(i = 0, ii = queue.length; i < ii; i++) {
716+
for (i = 0, ii = queue.length; i < ii; i++) {
717717
var invokeArgs = queue[i],
718718
provider = providerInjector.get(invokeArgs[0]);
719719

@@ -793,7 +793,7 @@ function createInjector(modulesToLoad, strictDi) {
793793
length, i,
794794
key;
795795

796-
for(i = 0, length = $inject.length; i < length; i++) {
796+
for (i = 0, length = $inject.length; i < length; i++) {
797797
key = $inject[i];
798798
if (typeof key !== 'string') {
799799
throw $injectorMinErr('itkn',

src/jqLite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ function jqLiteController(element, name) {
423423
function jqLiteInheritedData(element, name, value) {
424424
// if element is the document object work with the html element instead
425425
// this makes $(document).scope() possible
426-
if(element.nodeType == NODE_TYPE_DOCUMENT) {
426+
if (element.nodeType == NODE_TYPE_DOCUMENT) {
427427
element = element.documentElement;
428428
}
429429
var names = isArray(name) ? name : [name];
@@ -983,7 +983,7 @@ forEach({
983983
JQLite.prototype[name] = function(arg1, arg2, arg3) {
984984
var value;
985985

986-
for(var i = 0, ii = this.length; i < ii; i++) {
986+
for (var i = 0, ii = this.length; i < ii; i++) {
987987
if (isUndefined(value)) {
988988
value = fn(this[i], arg1, arg2, arg3);
989989
if (isDefined(value)) {

src/ng/animate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ var $AnimateProvider = ['$provide', function($provide) {
7575
* @return {RegExp} The current CSS className expression value. If null then there is no expression value
7676
*/
7777
this.classNameFilter = function(expression) {
78-
if(arguments.length === 1) {
78+
if (arguments.length === 1) {
7979
this.$$classNameFilter = (expression instanceof RegExp) ? expression : null;
8080
}
8181
return this.$$classNameFilter;

src/ng/browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function Browser(window, document, $log, $sniffer) {
5151
} finally {
5252
outstandingRequestCount--;
5353
if (outstandingRequestCount === 0) {
54-
while(outstandingRequestCallbacks.length) {
54+
while (outstandingRequestCallbacks.length) {
5555
try {
5656
outstandingRequestCallbacks.pop()();
5757
} catch (e) {

src/ng/compile.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
854854
*/
855855
var debugInfoEnabled = true;
856856
this.debugInfoEnabled = function(enabled) {
857-
if(isDefined(enabled)) {
857+
if (isDefined(enabled)) {
858858
debugInfoEnabled = enabled;
859859
return this;
860860
}
@@ -899,7 +899,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
899899
* @param {string} classVal The className value that will be added to the element
900900
*/
901901
$addClass : function(classVal) {
902-
if(classVal && classVal.length > 0) {
902+
if (classVal && classVal.length > 0) {
903903
$animate.addClass(this.$$element, classVal);
904904
}
905905
},
@@ -916,7 +916,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
916916
* @param {string} classVal The className value that will be removed from the element
917917
*/
918918
$removeClass : function(classVal) {
919-
if(classVal && classVal.length > 0) {
919+
if (classVal && classVal.length > 0) {
920920
$animate.removeClass(this.$$element, classVal);
921921
}
922922
},
@@ -969,7 +969,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
969969
if (booleanKey) {
970970
this.$$element.prop(key, value);
971971
attrName = booleanKey;
972-
} else if(aliasedKey) {
972+
} else if (aliasedKey) {
973973
this[aliasedKey] = value;
974974
observer = aliasedKey;
975975
}
@@ -1022,7 +1022,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10221022
result += $$sanitizeUri(trim(lastTuple[0]), true);
10231023

10241024
// and add the last descriptor if any
1025-
if( lastTuple.length === 2) {
1025+
if (lastTuple.length === 2) {
10261026
result += (" " + trim(lastTuple[1]));
10271027
}
10281028
this[key] = value = result;
@@ -1089,7 +1089,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
10891089
function safeAddClass($element, className) {
10901090
try {
10911091
$element.addClass(className);
1092-
} catch(e) {
1092+
} catch (e) {
10931093
// ignore, since it means that we are trying to set class on
10941094
// SVG element, where class name is read-only.
10951095
}
@@ -1278,7 +1278,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
12781278
stableNodeList = nodeList;
12791279
}
12801280

1281-
for(i = 0, ii = linkFns.length; i < ii;) {
1281+
for (i = 0, ii = linkFns.length; i < ii;) {
12821282
node = stableNodeList[linkFns[i++]];
12831283
nodeLinkFn = linkFns[i++];
12841284
childLinkFn = linkFns[i++];
@@ -1346,7 +1346,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13461346
match,
13471347
className;
13481348

1349-
switch(nodeType) {
1349+
switch (nodeType) {
13501350
case NODE_TYPE_ELEMENT: /* Element */
13511351
// use the node name: <directive>
13521352
addDirective(directives,
@@ -1522,7 +1522,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15221522
directiveValue;
15231523

15241524
// executes all directives on the current element
1525-
for(var i = 0, ii = directives.length; i < ii; i++) {
1525+
for (var i = 0, ii = directives.length; i < ii; i++) {
15261526
directive = directives[i];
15271527
var attrStart = directive.$$start;
15281528
var attrEnd = directive.$$end;
@@ -1855,7 +1855,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18551855
isolateBindingContext[scopeName] = value;
18561856
});
18571857
attrs.$$observers[attrName].$$scope = scope;
1858-
if( attrs[attrName] ) {
1858+
if ( attrs[attrName] ) {
18591859
// If the attribute has been provided then we trigger an interpolation to ensure
18601860
// the value is there for use in the link fn
18611861
isolateBindingContext[scopeName] = $interpolate(attrs[attrName])(scope);
@@ -1915,7 +1915,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19151915
}
19161916

19171917
// PRELINKING
1918-
for(i = 0, ii = preLinkFns.length; i < ii; i++) {
1918+
for (i = 0, ii = preLinkFns.length; i < ii; i++) {
19191919
linkFn = preLinkFns[i];
19201920
invokeLinkFn(linkFn,
19211921
linkFn.isolateScope ? isolateScope : scope,
@@ -1936,7 +1936,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19361936
childLinkFn && childLinkFn(scopeToChild, linkNode.childNodes, undefined, boundTranscludeFn);
19371937

19381938
// POSTLINKING
1939-
for(i = postLinkFns.length - 1; i >= 0; i--) {
1939+
for (i = postLinkFns.length - 1; i >= 0; i--) {
19401940
linkFn = postLinkFns[i];
19411941
invokeLinkFn(linkFn,
19421942
linkFn.isolateScope ? isolateScope : scope,
@@ -1996,7 +1996,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19961996
if (name === ignoreDirective) return null;
19971997
var match = null;
19981998
if (hasDirectives.hasOwnProperty(name)) {
1999-
for(var directive, directives = $injector.get(name + Suffix),
1999+
for (var directive, directives = $injector.get(name + Suffix),
20002000
i = 0, ii = directives.length; i<ii; i++) {
20012001
try {
20022002
directive = directives[i];
@@ -2008,7 +2008,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20082008
tDirectives.push(directive);
20092009
match = directive;
20102010
}
2011-
} catch(e) { $exceptionHandler(e); }
2011+
} catch (e) { $exceptionHandler(e); }
20122012
}
20132013
}
20142014
return match;
@@ -2025,7 +2025,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20252025
*/
20262026
function directiveIsMultiElement(name) {
20272027
if (hasDirectives.hasOwnProperty(name)) {
2028-
for(var directive, directives = $injector.get(name + Suffix),
2028+
for (var directive, directives = $injector.get(name + Suffix),
20292029
i = 0, ii = directives.length; i<ii; i++) {
20302030
directive = directives[i];
20312031
if (directive.multiElement) {
@@ -2142,7 +2142,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
21422142
});
21432143
afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);
21442144

2145-
while(linkQueue.length) {
2145+
while (linkQueue.length) {
21462146
var scope = linkQueue.shift(),
21472147
beforeTemplateLinkNode = linkQueue.shift(),
21482148
linkRootElement = linkQueue.shift(),
@@ -2241,7 +2241,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22412241

22422242
function wrapTemplate(type, template) {
22432243
type = lowercase(type || 'html');
2244-
switch(type) {
2244+
switch (type) {
22452245
case 'svg':
22462246
case 'math':
22472247
var wrapper = document.createElement('div');
@@ -2322,7 +2322,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23222322
//skip animations when the first digest occurs (when
23232323
//both the new and the old values are the same) since
23242324
//the CSS classes are the non-interpolated values
2325-
if(name === 'class' && newValue != oldValue) {
2325+
if (name === 'class' && newValue != oldValue) {
23262326
attr.$updateClass(newValue, oldValue);
23272327
} else {
23282328
attr.$set(name, newValue);
@@ -2352,7 +2352,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
23522352
i, ii;
23532353

23542354
if ($rootElement) {
2355-
for(i = 0, ii = $rootElement.length; i < ii; i++) {
2355+
for (i = 0, ii = $rootElement.length; i < ii; i++) {
23562356
if ($rootElement[i] == firstElementToRemove) {
23572357
$rootElement[i++] = newNode;
23582358
for (var j = i, j2 = j + removeCount - 1,
@@ -2427,7 +2427,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24272427
function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) {
24282428
try {
24292429
linkFn(scope, $element, attrs, controllers, transcludeFn);
2430-
} catch(e) {
2430+
} catch (e) {
24312431
$exceptionHandler(e, startingTag($element));
24322432
}
24332433
}
@@ -2516,10 +2516,10 @@ function tokenDifference(str1, str2) {
25162516
tokens2 = str2.split(/\s+/);
25172517

25182518
outer:
2519-
for(var i = 0; i < tokens1.length; i++) {
2519+
for (var i = 0; i < tokens1.length; i++) {
25202520
var token = tokens1[i];
2521-
for(var j = 0; j < tokens2.length; j++) {
2522-
if(token == tokens2[j]) continue outer;
2521+
for (var j = 0; j < tokens2.length; j++) {
2522+
if (token == tokens2[j]) continue outer;
25232523
}
25242524
values += (values.length > 0 ? ' ' : '') + token;
25252525
}

src/ng/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function $ControllerProvider() {
8282
identifier = ident;
8383
}
8484

85-
if(isString(expression)) {
85+
if (isString(expression)) {
8686
match = expression.match(CNTRL_REG),
8787
constructor = match[1],
8888
identifier = identifier || match[3];

src/ng/directive/input.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
21072107
var parserValid = isUndefined(modelValue) ? undefined : true;
21082108

21092109
if (parserValid) {
2110-
for(var i = 0; i < ctrl.$parsers.length; i++) {
2110+
for (var i = 0; i < ctrl.$parsers.length; i++) {
21112111
modelValue = ctrl.$parsers[i](modelValue);
21122112
if (isUndefined(modelValue)) {
21132113
parserValid = false;
@@ -2148,7 +2148,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
21482148
forEach(ctrl.$viewChangeListeners, function(listener) {
21492149
try {
21502150
listener();
2151-
} catch(e) {
2151+
} catch (e) {
21522152
$exceptionHandler(e);
21532153
}
21542154
});
@@ -2251,7 +2251,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
22512251
idx = formatters.length;
22522252

22532253
var viewValue = modelValue;
2254-
while(idx--) {
2254+
while (idx--) {
22552255
viewValue = formatters[idx](viewValue);
22562256
}
22572257
if (ctrl.$viewValue !== viewValue) {

src/ng/directive/ngClass.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ function classDirective(name, selector) {
8585
var values = [];
8686

8787
outer:
88-
for(var i = 0; i < tokens1.length; i++) {
88+
for (var i = 0; i < tokens1.length; i++) {
8989
var token = tokens1[i];
90-
for(var j = 0; j < tokens2.length; j++) {
91-
if(token == tokens2[j]) continue outer;
90+
for (var j = 0; j < tokens2.length; j++) {
91+
if (token == tokens2[j]) continue outer;
9292
}
9393
values.push(token);
9494
}

0 commit comments

Comments
 (0)