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

Commit e21b6ff

Browse files
hzoopkozlowski-opensource
authored andcommitted
style(*): add rule requireSpacesInConditionalExpression
Closes #9973
1 parent 06016bb commit e21b6ff

File tree

7 files changed

+56
-50
lines changed

7 files changed

+56
-50
lines changed

.jscs.json

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
"requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"],
2828
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
2929
"requireSpaceBeforeBlockStatements": true,
30+
"requireSpacesInConditionalExpression": {
31+
"afterTest": true,
32+
"beforeConsequent": true,
33+
"afterConsequent": true,
34+
"beforeAlternate": true
35+
},
3036
"requireSpacesInFunction": {
3137
"beforeOpeningCurlyBrace": true
3238
},

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
12321232
if (!node) {
12331233
return 'html';
12341234
} else {
1235-
return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg': 'html';
1235+
return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg' : 'html';
12361236
}
12371237
}
12381238

src/ng/filter/orderBy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ orderByFilter.$inject = ['$parse'];
119119
function orderByFilter($parse) {
120120
return function(array, sortPredicate, reverseOrder) {
121121
if (!(isArrayLike(array))) return array;
122-
sortPredicate = isArray(sortPredicate) ? sortPredicate: [sortPredicate];
122+
sortPredicate = isArray(sortPredicate) ? sortPredicate : [sortPredicate];
123123
if (sortPredicate.length === 0) { sortPredicate = ['+']; }
124124
sortPredicate = sortPredicate.map(function(predicate) {
125125
var descending = false, get = predicate || identity;

src/ng/parse.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ var OPERATORS = extend(createMap(), {
109109
}
110110
return a;
111111
}
112-
return isDefined(b)?b:undefined;},
112+
return isDefined(b) ? b : undefined;},
113113
'-':function(self, locals, a, b) {
114114
a=a(self, locals); b=b(self, locals);
115-
return (isDefined(a)?a:0) - (isDefined(b)?b:0);
115+
return (isDefined(a) ? a : 0) - (isDefined(b) ? b : 0);
116116
},
117117
'*':function(self, locals, a, b) {return a(self, locals) * b(self, locals);},
118118
'/':function(self, locals, a, b) {return a(self, locals) / b(self, locals);},

test/helpers/matchers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ beforeEach(function() {
4545
toBeTouched: cssMatcher('ng-touched', 'ng-untouched'),
4646
toBeAPromise: function() {
4747
this.message = valueFn(
48-
"Expected object " + (this.isNot ? "not ": "") + "to be a promise");
48+
"Expected object " + (this.isNot ? "not " : "") + "to be a promise");
4949
return isPromiseLike(this.actual);
5050
},
5151
toBeShown: function() {
5252
this.message = valueFn(
53-
"Expected element " + (this.isNot ? "": "not ") + "to have 'ng-hide' class");
53+
"Expected element " + (this.isNot ? "" : "not ") + "to have 'ng-hide' class");
5454
return !isNgElementHidden(this.actual);
5555
},
5656
toBeHidden: function() {
5757
this.message = valueFn(
58-
"Expected element " + (this.isNot ? "not ": "") + "to have 'ng-hide' class");
58+
"Expected element " + (this.isNot ? "not " : "") + "to have 'ng-hide' class");
5959
return isNgElementHidden(this.actual);
6060
},
6161

test/helpers/testabilityPatch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function sortedHtml(element, showNgClass) {
152152

153153
if (node.nodeName == "#text") {
154154
html += node.nodeValue.
155-
replace(/&(\w+[&;\W])?/g, function(match, entity) {return entity?match:'&amp;';}).
155+
replace(/&(\w+[&;\W])?/g, function(match, entity) {return entity ? match : '&amp;';}).
156156
replace(/</g, '&lt;').
157157
replace(/>/g, '&gt;');
158158
} else if (node.nodeName == "#comment") {

test/ng/parseSpec.js

+42-42
Original file line numberDiff line numberDiff line change
@@ -269,54 +269,54 @@ describe('parser', function() {
269269
var identity = scope.identity = function(x) { return x; };
270270

271271
// Simple.
272-
expect(scope.$eval('0?0:2')).toEqual(0?0:2);
273-
expect(scope.$eval('1?0:2')).toEqual(1?0:2);
272+
expect(scope.$eval('0?0:2')).toEqual(0 ? 0 : 2);
273+
expect(scope.$eval('1?0:2')).toEqual(1 ? 0 : 2);
274274

275275
// Nested on the left.
276-
expect(scope.$eval('0?0?0:0:2')).toEqual(0?0?0:0:2);
277-
expect(scope.$eval('1?0?0:0:2')).toEqual(1?0?0:0:2);
278-
expect(scope.$eval('0?1?0:0:2')).toEqual(0?1?0:0:2);
279-
expect(scope.$eval('0?0?1:0:2')).toEqual(0?0?1:0:2);
280-
expect(scope.$eval('0?0?0:2:3')).toEqual(0?0?0:2:3);
281-
expect(scope.$eval('1?1?0:0:2')).toEqual(1?1?0:0:2);
282-
expect(scope.$eval('1?1?1:0:2')).toEqual(1?1?1:0:2);
283-
expect(scope.$eval('1?1?1:2:3')).toEqual(1?1?1:2:3);
284-
expect(scope.$eval('1?1?1:2:3')).toEqual(1?1?1:2:3);
276+
expect(scope.$eval('0?0?0:0:2')).toEqual(0 ? 0 ? 0 : 0 : 2);
277+
expect(scope.$eval('1?0?0:0:2')).toEqual(1 ? 0 ? 0 : 0 : 2);
278+
expect(scope.$eval('0?1?0:0:2')).toEqual(0 ? 1 ? 0 : 0 : 2);
279+
expect(scope.$eval('0?0?1:0:2')).toEqual(0 ? 0 ? 1 : 0 : 2);
280+
expect(scope.$eval('0?0?0:2:3')).toEqual(0 ? 0 ? 0 : 2 : 3);
281+
expect(scope.$eval('1?1?0:0:2')).toEqual(1 ? 1 ? 0 : 0 : 2);
282+
expect(scope.$eval('1?1?1:0:2')).toEqual(1 ? 1 ? 1 : 0 : 2);
283+
expect(scope.$eval('1?1?1:2:3')).toEqual(1 ? 1 ? 1 : 2 : 3);
284+
expect(scope.$eval('1?1?1:2:3')).toEqual(1 ? 1 ? 1 : 2 : 3);
285285

286286
// Nested on the right.
287-
expect(scope.$eval('0?0:0?0:2')).toEqual(0?0:0?0:2);
288-
expect(scope.$eval('1?0:0?0:2')).toEqual(1?0:0?0:2);
289-
expect(scope.$eval('0?1:0?0:2')).toEqual(0?1:0?0:2);
290-
expect(scope.$eval('0?0:1?0:2')).toEqual(0?0:1?0:2);
291-
expect(scope.$eval('0?0:0?2:3')).toEqual(0?0:0?2:3);
292-
expect(scope.$eval('1?1:0?0:2')).toEqual(1?1:0?0:2);
293-
expect(scope.$eval('1?1:1?0:2')).toEqual(1?1:1?0:2);
294-
expect(scope.$eval('1?1:1?2:3')).toEqual(1?1:1?2:3);
295-
expect(scope.$eval('1?1:1?2:3')).toEqual(1?1:1?2:3);
287+
expect(scope.$eval('0?0:0?0:2')).toEqual(0 ? 0 : 0 ? 0 : 2);
288+
expect(scope.$eval('1?0:0?0:2')).toEqual(1 ? 0 : 0 ? 0 : 2);
289+
expect(scope.$eval('0?1:0?0:2')).toEqual(0 ? 1 : 0 ? 0 : 2);
290+
expect(scope.$eval('0?0:1?0:2')).toEqual(0 ? 0 : 1 ? 0 : 2);
291+
expect(scope.$eval('0?0:0?2:3')).toEqual(0 ? 0 : 0 ? 2 : 3);
292+
expect(scope.$eval('1?1:0?0:2')).toEqual(1 ? 1 : 0 ? 0 : 2);
293+
expect(scope.$eval('1?1:1?0:2')).toEqual(1 ? 1 : 1 ? 0 : 2);
294+
expect(scope.$eval('1?1:1?2:3')).toEqual(1 ? 1 : 1 ? 2 : 3);
295+
expect(scope.$eval('1?1:1?2:3')).toEqual(1 ? 1 : 1 ? 2 : 3);
296296

297297
// Precedence with respect to logical operators.
298-
expect(scope.$eval('0&&1?0:1')).toEqual(0 && 1?0:1);
299-
expect(scope.$eval('1||0?0:0')).toEqual(1 || 0?0:0);
300-
301-
expect(scope.$eval('0?0&&1:2')).toEqual(0?0 && 1:2);
302-
expect(scope.$eval('0?1&&1:2')).toEqual(0?1 && 1:2);
303-
expect(scope.$eval('0?0||0:1')).toEqual(0?0 || 0:1);
304-
expect(scope.$eval('0?0||1:2')).toEqual(0?0 || 1:2);
305-
306-
expect(scope.$eval('1?0&&1:2')).toEqual(1?0 && 1:2);
307-
expect(scope.$eval('1?1&&1:2')).toEqual(1?1 && 1:2);
308-
expect(scope.$eval('1?0||0:1')).toEqual(1?0 || 0:1);
309-
expect(scope.$eval('1?0||1:2')).toEqual(1?0 || 1:2);
310-
311-
expect(scope.$eval('0?1:0&&1')).toEqual(0?1:0 && 1);
312-
expect(scope.$eval('0?2:1&&1')).toEqual(0?2:1 && 1);
313-
expect(scope.$eval('0?1:0||0')).toEqual(0?1:0 || 0);
314-
expect(scope.$eval('0?2:0||1')).toEqual(0?2:0 || 1);
315-
316-
expect(scope.$eval('1?1:0&&1')).toEqual(1?1:0 && 1);
317-
expect(scope.$eval('1?2:1&&1')).toEqual(1?2:1 && 1);
318-
expect(scope.$eval('1?1:0||0')).toEqual(1?1:0 || 0);
319-
expect(scope.$eval('1?2:0||1')).toEqual(1?2:0 || 1);
298+
expect(scope.$eval('0&&1?0:1')).toEqual(0 && 1 ? 0 : 1);
299+
expect(scope.$eval('1||0?0:0')).toEqual(1 || 0 ? 0 : 0);
300+
301+
expect(scope.$eval('0?0&&1:2')).toEqual(0 ? 0 && 1 : 2);
302+
expect(scope.$eval('0?1&&1:2')).toEqual(0 ? 1 && 1 : 2);
303+
expect(scope.$eval('0?0||0:1')).toEqual(0 ? 0 || 0 : 1);
304+
expect(scope.$eval('0?0||1:2')).toEqual(0 ? 0 || 1 : 2);
305+
306+
expect(scope.$eval('1?0&&1:2')).toEqual(1 ? 0 && 1 : 2);
307+
expect(scope.$eval('1?1&&1:2')).toEqual(1 ? 1 && 1 : 2);
308+
expect(scope.$eval('1?0||0:1')).toEqual(1 ? 0 || 0 : 1);
309+
expect(scope.$eval('1?0||1:2')).toEqual(1 ? 0 || 1 : 2);
310+
311+
expect(scope.$eval('0?1:0&&1')).toEqual(0 ? 1 : 0 && 1);
312+
expect(scope.$eval('0?2:1&&1')).toEqual(0 ? 2 : 1 && 1);
313+
expect(scope.$eval('0?1:0||0')).toEqual(0 ? 1 : 0 || 0);
314+
expect(scope.$eval('0?2:0||1')).toEqual(0 ? 2 : 0 || 1);
315+
316+
expect(scope.$eval('1?1:0&&1')).toEqual(1 ? 1 : 0 && 1);
317+
expect(scope.$eval('1?2:1&&1')).toEqual(1 ? 2 : 1 && 1);
318+
expect(scope.$eval('1?1:0||0')).toEqual(1 ? 1 : 0 || 0);
319+
expect(scope.$eval('1?2:0||1')).toEqual(1 ? 2 : 0 || 1);
320320

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

0 commit comments

Comments
 (0)