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

Adding jscs rules #9685

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .jscs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": ["!"],
"disallowSpaceBeforeBinaryOperators": [","],
"disallowSpaceAfterObjectKeys": true,
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"]
"disallowSpacesInsideParentheses": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"validateParameterSeparator": ", "
}
12 changes: 6 additions & 6 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function sortedKeys(obj) {

function forEachSorted(obj, iterator, context) {
var keys = sortedKeys(obj);
for ( var i = 0; i < keys.length; i++) {
for (var i = 0; i < keys.length; i++) {
iterator.call(context, obj[keys[i]], keys[i]);
}
return keys;
Expand Down Expand Up @@ -626,7 +626,7 @@ function isElement(node) {
*/
function makeMap(str) {
var obj = {}, items = str.split(","), i;
for ( i = 0; i < items.length; i++ )
for (i = 0; i < items.length; i++)
obj[ items[i] ] = true;
return obj;
}
Expand Down Expand Up @@ -784,7 +784,7 @@ function copy(source, destination, stackSource, stackDest) {
var result;
if (isArray(source)) {
destination.length = 0;
for ( var i = 0; i < source.length; i++) {
for (var i = 0; i < source.length; i++) {
result = copy(source[i], null, stackSource, stackDest);
if (isObject(source[i])) {
stackSource.push(source[i]);
Expand All @@ -801,7 +801,7 @@ function copy(source, destination, stackSource, stackDest) {
delete destination[key];
});
}
for ( var key in source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
result = copy(source[key], null, stackSource, stackDest);
if (isObject(source[key])) {
Expand Down Expand Up @@ -1089,10 +1089,10 @@ function tryDecodeURIComponent(value) {
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
forEach((keyValue || "").split('&'), function(keyValue) {
if ( keyValue ) {
if (keyValue) {
key_value = keyValue.replace(/\+/g,'%20').split('=');
key = tryDecodeURIComponent(key_value[0]);
if ( isDefined(key) ) {
if (isDefined(key)) {
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
if (!hasOwnProperty.call(obj, key)) {
obj[key] = val;
Expand Down
6 changes: 3 additions & 3 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ function jqLiteData(element, key, value) {
function jqLiteHasClass(element, selector) {
if (!element.getAttribute) return false;
return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " ").
indexOf( " " + selector + " " ) > -1);
indexOf(" " + selector + " ") > -1);
}

function jqLiteRemoveClass(element, cssClasses) {
Expand Down Expand Up @@ -417,7 +417,7 @@ function jqLiteAddNodes(root, elements) {


function jqLiteController(element, name) {
return jqLiteInheritedData(element, '$' + (name || 'ngController' ) + 'Controller');
return jqLiteInheritedData(element, '$' + (name || 'ngController') + 'Controller');
}

function jqLiteInheritedData(element, name, value) {
Expand Down Expand Up @@ -802,7 +802,7 @@ forEach({
var target = this, related = event.relatedTarget;
// For mousenter/leave call the handler if related is outside the target.
// NB: No relatedTarget if the mouse left/entered the browser window
if ( !related || (related !== target && !target.contains(related)) ){
if (!related || (related !== target && !target.contains(related))){
handle(event, type);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/ng/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ function Browser(window, document, $log, $sniffer) {

function $BrowserProvider(){
this.$get = ['$window', '$log', '$sniffer', '$document',
function( $window, $log, $sniffer, $document){
function($window, $log, $sniffer, $document){
return new Browser($window, $document, $log, $sniffer);
}];
}
12 changes: 6 additions & 6 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
for (var i=0; i<nbrUrisWith2parts; i++) {
var innerIdx = i*2;
// sanitize the uri
result += $$sanitizeUri(trim( rawUris[innerIdx]), true);
result += $$sanitizeUri(trim(rawUris[innerIdx]), true);
// add the descriptor
result += ( " " + trim(rawUris[innerIdx+1]));
result += (" " + trim(rawUris[innerIdx+1]));
}

// split the last item into uri and descriptor
Expand Down Expand Up @@ -1291,7 +1291,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
childScope = scope;
}

if ( nodeLinkFn.transcludeOnThisElement ) {
if (nodeLinkFn.transcludeOnThisElement) {
childBoundTranscludeFn = createBoundTranscludeFn(
scope, nodeLinkFn.transclude, parentBoundTranscludeFn,
nodeLinkFn.elementTranscludeOnThisElement);
Expand Down Expand Up @@ -1855,7 +1855,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
isolateBindingContext[scopeName] = value;
});
attrs.$$observers[attrName].$$scope = scope;
if ( attrs[attrName] ) {
if (attrs[attrName]) {
// If the attribute has been provided then we trigger an interpolation to ensure
// the value is there for use in the link fn
isolateBindingContext[scopeName] = $interpolate(attrs[attrName])(scope);
Expand All @@ -1870,7 +1870,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (parentGet.literal) {
compare = equals;
} else {
compare = function(a,b) { return a === b || (a !== a && b !== b); };
compare = function(a, b) { return a === b || (a !== a && b !== b); };
}
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
Expand Down Expand Up @@ -2000,7 +2000,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
i = 0, ii = directives.length; i<ii; i++) {
try {
directive = directives[i];
if ( (maxPriority === undefined || maxPriority > directive.priority) &&
if ((maxPriority === undefined || maxPriority > directive.priority) &&
directive.restrict.indexOf(location) != -1) {
if (startAttrName) {
directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
key = index;
if (keyName) {
key = keys[index];
if ( key.charAt(0) === '$' ) continue;
if (key.charAt(0) === '$') continue;
}
value = values[key];

Expand Down
6 changes: 3 additions & 3 deletions src/ng/filter/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function filterFilter() {
case 'object':
return comparator(obj, text);
default:
for ( var objKey in obj) {
for (var objKey in obj) {
if (objKey.charAt(0) !== '$' && search(obj[objKey], text)) {
return true;
}
Expand All @@ -176,7 +176,7 @@ function filterFilter() {
}
return false;
case 'array':
for ( var i = 0; i < obj.length; i++) {
for (var i = 0; i < obj.length; i++) {
if (search(obj[i], text)) {
return true;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ function filterFilter() {
return array;
}
var filtered = [];
for ( var j = 0; j < array.length; j++) {
for (var j = 0; j < array.length; j++) {
var value = array[j];
if (predicates.check(value, j)) {
filtered.push(value);
Expand Down
2 changes: 1 addition & 1 deletion src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function dateGetter(name, size, offset, trim) {
var value = date['get' + name]();
if (offset > 0 || value > -offset)
value += offset;
if (value === 0 && offset == -12 ) value = 12;
if (value === 0 && offset == -12) value = 12;
return padNumber(value, size, trim);
};
}
Expand Down
14 changes: 7 additions & 7 deletions src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,38 @@ function orderByFilter($parse){
descending = predicate.charAt(0) == '-';
predicate = predicate.substring(1);
}
if ( predicate === '' ) {
if (predicate === '') {
// Effectively no predicate was passed so we compare identity
return reverseComparator(function(a,b) {
return reverseComparator(function(a, b) {
return compare(a, b);
}, descending);
}
get = $parse(predicate);
if (get.constant) {
var key = get();
return reverseComparator(function(a,b) {
return reverseComparator(function(a, b) {
return compare(a[key], b[key]);
}, descending);
}
}
return reverseComparator(function(a,b){
return reverseComparator(function(a, b){
return compare(get(a),get(b));
}, descending);
});
var arrayCopy = [];
for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
for (var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
return arrayCopy.sort(reverseComparator(comparator, reverseOrder));

function comparator(o1, o2){
for ( var i = 0; i < sortPredicate.length; i++) {
for (var i = 0; i < sortPredicate.length; i++) {
var comp = sortPredicate[i](o1, o2);
if (comp !== 0) return comp;
}
return 0;
}
function reverseComparator(comp, descending) {
return descending
? function(a,b){return comp(b,a);}
? function(a, b){return comp(b,a);}
: comp;
}
function compare(v1, v2){
Expand Down
4 changes: 2 additions & 2 deletions src/ng/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ function $InterpolateProvider() {
expressionPositions = [];

while (index < textLength) {
if ( ((startIndex = text.indexOf(startSymbol, index)) != -1) &&
((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1) ) {
if (((startIndex = text.indexOf(startSymbol, index)) != -1) &&
((endIndex = text.indexOf(endSymbol, startIndex + startSymbolLength)) != -1)) {
if (index !== startIndex) {
concat.push(unescapeText(text.substring(index, startIndex)));
}
Expand Down
14 changes: 7 additions & 7 deletions src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ function LocationHtml5Url(appBase, basePrefix) {
var appUrl, prevAppUrl;
var rewrittenUrl;

if ( (appUrl = beginsWith(appBase, url)) !== undefined ) {
if ((appUrl = beginsWith(appBase, url)) !== undefined) {
prevAppUrl = appUrl;
if ( (appUrl = beginsWith(basePrefix, appUrl)) !== undefined ) {
if ((appUrl = beginsWith(basePrefix, appUrl)) !== undefined) {
rewrittenUrl = appBaseNoFile + (beginsWith('/', appUrl) || appUrl);
} else {
rewrittenUrl = appBase + prevAppUrl;
}
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) !== undefined ) {
} else if ((appUrl = beginsWith(appBaseNoFile, url)) !== undefined) {
rewrittenUrl = appBaseNoFile + appUrl;
} else if (appBaseNoFile == url + '/') {
rewrittenUrl = appBaseNoFile;
Expand Down Expand Up @@ -278,11 +278,11 @@ function LocationHashbangInHtml5Url(appBase, hashPrefix) {
var rewrittenUrl;
var appUrl;

if ( appBase == stripHash(url) ) {
if (appBase == stripHash(url)) {
rewrittenUrl = url;
} else if ( (appUrl = beginsWith(appBaseNoFile, url)) ) {
} else if ((appUrl = beginsWith(appBaseNoFile, url))) {
rewrittenUrl = appBase + hashPrefix + appUrl;
} else if ( appBaseNoFile === url + '/') {
} else if (appBaseNoFile === url + '/') {
rewrittenUrl = appBaseNoFile;
}
if (rewrittenUrl) {
Expand Down Expand Up @@ -728,7 +728,7 @@ function $LocationProvider(){
*/

this.$get = ['$rootScope', '$browser', '$sniffer', '$rootElement',
function( $rootScope, $browser, $sniffer, $rootElement) {
function($rootScope, $browser, $sniffer, $rootElement) {
var $location,
LocationMode,
baseHref = $browser.baseHref(), // if base[href] is undefined, it defaults to ''
Expand Down
26 changes: 13 additions & 13 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ CONSTANTS['this'].sharedGetter = true;

//Operators - will be wrapped by binaryFn/unaryFn/assignment/filter
var OPERATORS = extend(createMap(), {
'+':function(self, locals, a,b){
'+':function(self, locals, a, b){
a=a(self, locals); b=b(self, locals);
if (isDefined(a)) {
if (isDefined(b)) {
Expand All @@ -108,23 +108,23 @@ var OPERATORS = extend(createMap(), {
return a;
}
return isDefined(b)?b:undefined;},
'-':function(self, locals, a,b){
'-':function(self, locals, a, b){
a=a(self, locals); b=b(self, locals);
return (isDefined(a)?a:0)-(isDefined(b)?b:0);
},
'*':function(self, locals, a,b){return a(self, locals)*b(self, locals);},
'/':function(self, locals, a,b){return a(self, locals)/b(self, locals);},
'%':function(self, locals, a,b){return a(self, locals)%b(self, locals);},
'*':function(self, locals, a, b){return a(self, locals)*b(self, locals);},
'/':function(self, locals, a, b){return a(self, locals)/b(self, locals);},
'%':function(self, locals, a, b){return a(self, locals)%b(self, locals);},
'===':function(self, locals, a, b){return a(self, locals)===b(self, locals);},
'!==':function(self, locals, a, b){return a(self, locals)!==b(self, locals);},
'==':function(self, locals, a,b){return a(self, locals)==b(self, locals);},
'!=':function(self, locals, a,b){return a(self, locals)!=b(self, locals);},
'<':function(self, locals, a,b){return a(self, locals)<b(self, locals);},
'>':function(self, locals, a,b){return a(self, locals)>b(self, locals);},
'<=':function(self, locals, a,b){return a(self, locals)<=b(self, locals);},
'>=':function(self, locals, a,b){return a(self, locals)>=b(self, locals);},
'&&':function(self, locals, a,b){return a(self, locals)&&b(self, locals);},
'||':function(self, locals, a,b){return a(self, locals)||b(self, locals);},
'==':function(self, locals, a, b){return a(self, locals)==b(self, locals);},
'!=':function(self, locals, a, b){return a(self, locals)!=b(self, locals);},
'<':function(self, locals, a, b){return a(self, locals)<b(self, locals);},
'>':function(self, locals, a, b){return a(self, locals)>b(self, locals);},
'<=':function(self, locals, a, b){return a(self, locals)<=b(self, locals);},
'>=':function(self, locals, a, b){return a(self, locals)>=b(self, locals);},
'&&':function(self, locals, a, b){return a(self, locals)&&b(self, locals);},
'||':function(self, locals, a, b){return a(self, locals)||b(self, locals);},
'!':function(self, locals, a){return !a(self, locals);},

//Tokenized as operators but parsed as assignment/filters
Expand Down
2 changes: 1 addition & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function $RootScopeProvider(){
};

this.$get = ['$injector', '$exceptionHandler', '$parse', '$browser',
function( $injector, $exceptionHandler, $parse, $browser) {
function($injector, $exceptionHandler, $parse, $browser) {

/**
* @ngdoc type
Expand Down
8 changes: 4 additions & 4 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ angular.mock.$Browser = function() {
self.defer = function(fn, delay) {
delay = delay || 0;
self.deferredFns.push({time:(self.defer.now + delay), fn:fn, id: self.deferredNextId});
self.deferredFns.sort(function(a,b){ return a.time - b.time;});
self.deferredFns.sort(function(a, b){ return a.time - b.time;});
return self.deferredNextId++;
};

Expand Down Expand Up @@ -497,7 +497,7 @@ angular.mock.$IntervalProvider = function() {
id: nextRepeatId,
deferred: deferred
});
repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
repeatFns.sort(function(a, b){ return a.nextTime - b.nextTime;});

nextRepeatId++;
return promise;
Expand Down Expand Up @@ -546,7 +546,7 @@ angular.mock.$IntervalProvider = function() {
var task = repeatFns[0];
task.fn();
task.nextTime += task.delay;
repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
repeatFns.sort(function(a, b){ return a.nextTime - b.nextTime;});
}
return millis;
};
Expand Down Expand Up @@ -876,7 +876,7 @@ angular.mock.dump = function(object) {
function serializeScope(scope, offset) {
offset = offset || ' ';
var log = [offset + 'Scope(' + scope.$id + '): {'];
for ( var key in scope ) {
for (var key in scope) {
if (Object.prototype.hasOwnProperty.call(scope, key) && !key.match(/^(\$|this)/)) {
log.push(' ' + key + ': ' + angular.toJson(scope[key]));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ngRouteModule.directive('ngView', ngViewFillContentFactory);
* Emitted every time the ngView content is reloaded.
*/
ngViewFactory.$inject = ['$route', '$anchorScroll', '$animate'];
function ngViewFactory( $route, $anchorScroll, $animate) {
function ngViewFactory($route, $anchorScroll, $animate) {
return {
restrict: 'ECA',
terminal: true,
Expand Down
Loading