Skip to content

Commit

Permalink
style(*): add rule requireSpacesInConditionalExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo authored and pkozlowski-opensource committed Nov 9, 2014
1 parent 06016bb commit e21b6ff
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 50 deletions.
6 changes: 6 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
"requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
},
Expand Down
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
if (!node) {
return 'html';
} else {
return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg': 'html';
return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg' : 'html';
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ng/filter/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ orderByFilter.$inject = ['$parse'];
function orderByFilter($parse) {
return function(array, sortPredicate, reverseOrder) {
if (!(isArrayLike(array))) return array;
sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
sortPredicate = isArray(sortPredicate) ? sortPredicate : [sortPredicate];
if (sortPredicate.length === 0) { sortPredicate = ['+']; }
sortPredicate = sortPredicate.map(function(predicate) {
var descending = false, get = predicate || identity;
Expand Down
4 changes: 2 additions & 2 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ var OPERATORS = extend(createMap(), {
}
return a;
}
return isDefined(b)?b:undefined;},
return isDefined(b) ? b : undefined;},
'-':function(self, locals, a, b) {
a=a(self, locals); b=b(self, locals);
return (isDefined(a)?a:0) - (isDefined(b)?b:0);
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);},
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ beforeEach(function() {
toBeTouched: cssMatcher('ng-touched', 'ng-untouched'),
toBeAPromise: function() {
this.message = valueFn(
"Expected object " + (this.isNot ? "not ": "") + "to be a promise");
"Expected object " + (this.isNot ? "not " : "") + "to be a promise");
return isPromiseLike(this.actual);
},
toBeShown: function() {
this.message = valueFn(
"Expected element " + (this.isNot ? "": "not ") + "to have 'ng-hide' class");
"Expected element " + (this.isNot ? "" : "not ") + "to have 'ng-hide' class");
return !isNgElementHidden(this.actual);
},
toBeHidden: function() {
this.message = valueFn(
"Expected element " + (this.isNot ? "not ": "") + "to have 'ng-hide' class");
"Expected element " + (this.isNot ? "not " : "") + "to have 'ng-hide' class");
return isNgElementHidden(this.actual);
},

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/testabilityPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function sortedHtml(element, showNgClass) {

if (node.nodeName == "#text") {
html += node.nodeValue.
replace(/&(\w+[&;\W])?/g, function(match, entity) {return entity?match:'&amp;';}).
replace(/&(\w+[&;\W])?/g, function(match, entity) {return entity ? match : '&amp;';}).
replace(/</g, '&lt;').
replace(/>/g, '&gt;');
} else if (node.nodeName == "#comment") {
Expand Down
84 changes: 42 additions & 42 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,54 +269,54 @@ describe('parser', function() {
var identity = scope.identity = function(x) { return x; };

// Simple.
expect(scope.$eval('0?0:2')).toEqual(0?0:2);
expect(scope.$eval('1?0:2')).toEqual(1?0:2);
expect(scope.$eval('0?0:2')).toEqual(0 ? 0 : 2);
expect(scope.$eval('1?0:2')).toEqual(1 ? 0 : 2);

// Nested on the left.
expect(scope.$eval('0?0?0:0:2')).toEqual(0?0?0:0:2);
expect(scope.$eval('1?0?0:0:2')).toEqual(1?0?0:0:2);
expect(scope.$eval('0?1?0:0:2')).toEqual(0?1?0:0:2);
expect(scope.$eval('0?0?1:0:2')).toEqual(0?0?1:0:2);
expect(scope.$eval('0?0?0:2:3')).toEqual(0?0?0:2:3);
expect(scope.$eval('1?1?0:0:2')).toEqual(1?1?0:0:2);
expect(scope.$eval('1?1?1:0:2')).toEqual(1?1?1:0:2);
expect(scope.$eval('1?1?1:2:3')).toEqual(1?1?1:2:3);
expect(scope.$eval('1?1?1:2:3')).toEqual(1?1?1:2:3);
expect(scope.$eval('0?0?0:0:2')).toEqual(0 ? 0 ? 0 : 0 : 2);
expect(scope.$eval('1?0?0:0:2')).toEqual(1 ? 0 ? 0 : 0 : 2);
expect(scope.$eval('0?1?0:0:2')).toEqual(0 ? 1 ? 0 : 0 : 2);
expect(scope.$eval('0?0?1:0:2')).toEqual(0 ? 0 ? 1 : 0 : 2);
expect(scope.$eval('0?0?0:2:3')).toEqual(0 ? 0 ? 0 : 2 : 3);
expect(scope.$eval('1?1?0:0:2')).toEqual(1 ? 1 ? 0 : 0 : 2);
expect(scope.$eval('1?1?1:0:2')).toEqual(1 ? 1 ? 1 : 0 : 2);
expect(scope.$eval('1?1?1:2:3')).toEqual(1 ? 1 ? 1 : 2 : 3);
expect(scope.$eval('1?1?1:2:3')).toEqual(1 ? 1 ? 1 : 2 : 3);

// Nested on the right.
expect(scope.$eval('0?0:0?0:2')).toEqual(0?0:0?0:2);
expect(scope.$eval('1?0:0?0:2')).toEqual(1?0:0?0:2);
expect(scope.$eval('0?1:0?0:2')).toEqual(0?1:0?0:2);
expect(scope.$eval('0?0:1?0:2')).toEqual(0?0:1?0:2);
expect(scope.$eval('0?0:0?2:3')).toEqual(0?0:0?2:3);
expect(scope.$eval('1?1:0?0:2')).toEqual(1?1:0?0:2);
expect(scope.$eval('1?1:1?0:2')).toEqual(1?1:1?0:2);
expect(scope.$eval('1?1:1?2:3')).toEqual(1?1:1?2:3);
expect(scope.$eval('1?1:1?2:3')).toEqual(1?1:1?2:3);
expect(scope.$eval('0?0:0?0:2')).toEqual(0 ? 0 : 0 ? 0 : 2);
expect(scope.$eval('1?0:0?0:2')).toEqual(1 ? 0 : 0 ? 0 : 2);
expect(scope.$eval('0?1:0?0:2')).toEqual(0 ? 1 : 0 ? 0 : 2);
expect(scope.$eval('0?0:1?0:2')).toEqual(0 ? 0 : 1 ? 0 : 2);
expect(scope.$eval('0?0:0?2:3')).toEqual(0 ? 0 : 0 ? 2 : 3);
expect(scope.$eval('1?1:0?0:2')).toEqual(1 ? 1 : 0 ? 0 : 2);
expect(scope.$eval('1?1:1?0:2')).toEqual(1 ? 1 : 1 ? 0 : 2);
expect(scope.$eval('1?1:1?2:3')).toEqual(1 ? 1 : 1 ? 2 : 3);
expect(scope.$eval('1?1:1?2:3')).toEqual(1 ? 1 : 1 ? 2 : 3);

// Precedence with respect to logical operators.
expect(scope.$eval('0&&1?0:1')).toEqual(0 && 1?0:1);
expect(scope.$eval('1||0?0:0')).toEqual(1 || 0?0:0);

expect(scope.$eval('0?0&&1:2')).toEqual(0?0 && 1:2);
expect(scope.$eval('0?1&&1:2')).toEqual(0?1 && 1:2);
expect(scope.$eval('0?0||0:1')).toEqual(0?0 || 0:1);
expect(scope.$eval('0?0||1:2')).toEqual(0?0 || 1:2);

expect(scope.$eval('1?0&&1:2')).toEqual(1?0 && 1:2);
expect(scope.$eval('1?1&&1:2')).toEqual(1?1 && 1:2);
expect(scope.$eval('1?0||0:1')).toEqual(1?0 || 0:1);
expect(scope.$eval('1?0||1:2')).toEqual(1?0 || 1:2);

expect(scope.$eval('0?1:0&&1')).toEqual(0?1:0 && 1);
expect(scope.$eval('0?2:1&&1')).toEqual(0?2:1 && 1);
expect(scope.$eval('0?1:0||0')).toEqual(0?1:0 || 0);
expect(scope.$eval('0?2:0||1')).toEqual(0?2:0 || 1);

expect(scope.$eval('1?1:0&&1')).toEqual(1?1:0 && 1);
expect(scope.$eval('1?2:1&&1')).toEqual(1?2:1 && 1);
expect(scope.$eval('1?1:0||0')).toEqual(1?1:0 || 0);
expect(scope.$eval('1?2:0||1')).toEqual(1?2:0 || 1);
expect(scope.$eval('0&&1?0:1')).toEqual(0 && 1 ? 0 : 1);
expect(scope.$eval('1||0?0:0')).toEqual(1 || 0 ? 0 : 0);

expect(scope.$eval('0?0&&1:2')).toEqual(0 ? 0 && 1 : 2);
expect(scope.$eval('0?1&&1:2')).toEqual(0 ? 1 && 1 : 2);
expect(scope.$eval('0?0||0:1')).toEqual(0 ? 0 || 0 : 1);
expect(scope.$eval('0?0||1:2')).toEqual(0 ? 0 || 1 : 2);

expect(scope.$eval('1?0&&1:2')).toEqual(1 ? 0 && 1 : 2);
expect(scope.$eval('1?1&&1:2')).toEqual(1 ? 1 && 1 : 2);
expect(scope.$eval('1?0||0:1')).toEqual(1 ? 0 || 0 : 1);
expect(scope.$eval('1?0||1:2')).toEqual(1 ? 0 || 1 : 2);

expect(scope.$eval('0?1:0&&1')).toEqual(0 ? 1 : 0 && 1);
expect(scope.$eval('0?2:1&&1')).toEqual(0 ? 2 : 1 && 1);
expect(scope.$eval('0?1:0||0')).toEqual(0 ? 1 : 0 || 0);
expect(scope.$eval('0?2:0||1')).toEqual(0 ? 2 : 0 || 1);

expect(scope.$eval('1?1:0&&1')).toEqual(1 ? 1 : 0 && 1);
expect(scope.$eval('1?2:1&&1')).toEqual(1 ? 2 : 1 && 1);
expect(scope.$eval('1?1:0||0')).toEqual(1 ? 1 : 0 || 0);
expect(scope.$eval('1?2:0||1')).toEqual(1 ? 2 : 0 || 1);

// Function calls.
expect(scope.$eval('returnTrue() ? returnString() : returnInt()')).toEqual(returnTrue() ? returnString() : returnInt());
Expand Down

0 comments on commit e21b6ff

Please sign in to comment.