diff --git a/.jscs.json b/.jscs.json index c79cbf6ef108..4e0292635483 100644 --- a/.jscs.json +++ b/.jscs.json @@ -23,8 +23,16 @@ "disallowTrailingWhitespace": true, "requireCommaBeforeLineBreak": true, "requireLineFeedAtFileEnd": true, + "requireSpaceAfterBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"], + "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 }, diff --git a/.jscs.json.todo b/.jscs.json.todo index a0a234d2ef89..3bc5806e86e0 100644 --- a/.jscs.json.todo +++ b/.jscs.json.todo @@ -5,8 +5,6 @@ { "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"], - "requireSpaceAfterBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"], - "requireSpaceBeforeBinaryOperators": ["?", ":", "+", "-", "/", "*", "%", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"], "disallowImplicitTypeConversion": ["string"], "disallowMultipleLineBreaks": true, "disallowKeywordsOnNewLine": ["else"], diff --git a/src/Angular.js b/src/Angular.js index 9377605bdd76..9d0142a16437 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -634,7 +634,7 @@ function includes(array, obj) { function arrayRemove(array, value) { var index = array.indexOf(value); - if (index >=0) + if (index >= 0) array.splice(index, 1); return value; } @@ -835,7 +835,7 @@ function equals(o1, o2) { if (isArray(o1)) { if (!isArray(o2)) return false; if ((length = o1.length) == o2.length) { - for (key=0; key 4096 bytes)!"); } } diff --git a/src/ng/compile.js b/src/ng/compile.js index e4b42e75a9c7..e1d08e60fd15 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1029,16 +1029,16 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { // for each tuples var nbrUrisWith2parts = Math.floor(rawUris.length / 2); - for (var i=0; i directive.priority) && @@ -2074,7 +2074,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { function directiveIsMultiElement(name) { if (hasDirectives.hasOwnProperty(name)) { for (var directive, directives = $injector.get(name + Suffix), - i = 0, ii = directives.length; i'+template+''; + wrapper.innerHTML = '<' + type + '>' + template + ''; return wrapper.childNodes[0].childNodes; default: return template; diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 639afcb9dfcb..43719c587a6b 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1063,8 +1063,8 @@ function createDateParser(regexp, mapping) { // When a date is JSON'ified to wraps itself inside of an extra // set of double quotes. This makes the date parsing code unable // to match the date string and parse it as a date. - if (iso.charAt(0) == '"' && iso.charAt(iso.length-1) == '"') { - iso = iso.substring(1, iso.length-1); + if (iso.charAt(0) == '"' && iso.charAt(iso.length - 1) == '"') { + iso = iso.substring(1, iso.length - 1); } if (ISO_DATE_REGEXP.test(iso)) { return new Date(iso); diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index f00228a91413..0909c90423fd 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -616,7 +616,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { lastElement = null; // start at the beginning for (index = 0, length = optionGroup.length; index < length; index++) { option = optionGroup[index]; - if ((existingOption = existingOptions[index+1])) { + if ((existingOption = existingOptions[index + 1])) { // reuse elements lastElement = existingOption.element; if (existingOption.label !== option.label) { diff --git a/src/ng/filter/filter.js b/src/ng/filter/filter.js index 9e72472abe7f..868199cf22cf 100644 --- a/src/ng/filter/filter.js +++ b/src/ng/filter/filter.js @@ -147,8 +147,8 @@ function filterFilter() { } return false; } - text = (''+text).toLowerCase(); - return (''+obj).toLowerCase().indexOf(text) > -1; + text = ('' + text).toLowerCase(); + return ('' + obj).toLowerCase().indexOf(text) > -1; }; } } diff --git a/src/ng/filter/filters.js b/src/ng/filter/filters.js index 4ca2f377b05e..65de6ccea705 100644 --- a/src/ng/filter/filters.js +++ b/src/ng/filter/filters.js @@ -187,7 +187,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { if (whole.length >= (lgroup + group)) { pos = whole.length - lgroup; for (i = 0; i < pos; i++) { - if ((pos - i)%group === 0 && i !== 0) { + if ((pos - i) % group === 0 && i !== 0) { formatedText += groupSep; } formatedText += whole.charAt(i); @@ -195,7 +195,7 @@ function formatNumber(number, pattern, groupSep, decimalSep, fractionSize) { } for (i = pos; i < whole.length; i++) { - if ((whole.length - i)%lgroup === 0 && i !== 0) { + if ((whole.length - i) % lgroup === 0 && i !== 0) { formatedText += groupSep; } formatedText += whole.charAt(i); @@ -435,10 +435,10 @@ function dateFilter($locale) { tzMin = int(match[9] + match[11]); } dateSetter.call(date, int(match[1]), int(match[2]) - 1, int(match[3])); - var h = int(match[4]||0) - tzHour; - var m = int(match[5]||0) - tzMin; - var s = int(match[6]||0); - var ms = Math.round(parseFloat('0.' + (match[7]||0)) * 1000); + var h = int(match[4] || 0) - tzHour; + var m = int(match[5] || 0) - tzMin; + var s = int(match[6] || 0); + var ms = Math.round(parseFloat('0.' + (match[7] || 0)) * 1000); timeSetter.call(date, h, m, s, ms); return date; } diff --git a/src/ng/filter/limitTo.js b/src/ng/filter/limitTo.js index a3f327ad4d9c..b07c5d7b7562 100644 --- a/src/ng/filter/limitTo.js +++ b/src/ng/filter/limitTo.js @@ -123,7 +123,7 @@ function limitToFilter() { n = input.length; } - for (; i':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 diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 43217c379995..df8ddcf6d4cc 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -1161,7 +1161,7 @@ function $RootScopeProvider() { do { namedListeners = scope.$$listeners[name] || empty; event.currentScope = scope; - for (i=0, length=namedListeners.length; i'+ + '
' + '' + - '
'+ + '
' + '' + - '
    '+ + '
      ' + '' + - '
        '+ + '
          ' + '' + - '
          '+ + '
          ' + '' + - '
          '+ + '
          ' + '' + - '
            '+ + '
              ' + '' + - '
                '+ + '
                  ' + '' + '
                  ' + '' + diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index 12f44c34622f..984deb4ac2d2 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -7,7 +7,7 @@ describe('injector', function() { beforeEach(module(function($provide, $injector) { providers = function(name, factory, annotations) { - $provide.factory(name, extend(factory, annotations||{})); + $provide.factory(name, extend(factory, annotations || {})); }; providerInjector = $injector; })); @@ -28,7 +28,7 @@ describe('injector', function() { it('should inject providers', function() { providers('a', function() {return 'Mi';}); - providers('b', function(mi) {return mi+'sko';}, {$inject:['a']}); + providers('b', function(mi) {return mi + 'sko';}, {$inject:['a']}); expect(injector.get('b')).toEqual('Misko'); }); diff --git a/test/e2e/tools/middleware.js b/test/e2e/tools/middleware.js index 39e88a176bab..8274ae43f605 100644 --- a/test/e2e/tools/middleware.js +++ b/test/e2e/tools/middleware.js @@ -8,7 +8,7 @@ module.exports = middlewareFactory; function middlewareFactory(base) { base = base || '/e2e'; - while (base.length && base[base.length-1] === '/') base = base.slice(0, base.length-1); + while (base.length && base[base.length - 1] === '/') base = base.slice(0, base.length - 1); var fixture_regexp = new RegExp('^' + base + '/fixtures/([a-zA-Z0-9_-]+)(/(index.html)?)?$'); var static_regexp = new RegExp('^' + base + '/fixtures/([a-zA-Z0-9_-]+)(/.*)$'); diff --git a/test/helpers/matchers.js b/test/helpers/matchers.js index 248843ecdaaa..91407c2f795e 100644 --- a/test/helpers/matchers.js +++ b/test/helpers/matchers.js @@ -29,7 +29,7 @@ beforeEach(function() { // we need to check element.getAttribute for SVG nodes var hidden = true; forEach(angular.element(element), function(element) { - if ((' ' +(element.getAttribute('class') || '') + ' ').indexOf(' ng-hide ') === -1) { + if ((' ' + (element.getAttribute('class') || '') + ' ').indexOf(' ng-hide ') === -1) { hidden = false; } }); @@ -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); }, @@ -168,7 +168,7 @@ beforeEach(function() { return "Expected '" + angular.mock.dump(this.actual) + "' to have class '" + clazz + "'."; }; var classes = clazz.trim().split(/\s+/); - for (var i=0; i/g, '>'); } else if (node.nodeName == "#comment") { @@ -169,26 +169,26 @@ function sortedHtml(element, showNgClass) { if (className) { attrs.push(' class="' + className + '"'); } - for (var i=0; i0 && attributes[i] == attributes[i-1]) + for (var i = 0; i < attributes.length; i++) { + if (i > 0 && attributes[i] == attributes[i - 1]) continue; //IE9 creates dupes. Ignore them! var attr = attributes[i]; if (attr.name.match(/^ng[\:\-]/) || (attr.value || attr.value === '') && - attr.value !='null' && - attr.value !='auto' && - attr.value !='false' && - attr.value !='inherit' && - (attr.value !='0' || attr.name =='value') && - attr.name !='loop' && - attr.name !='complete' && - attr.name !='maxLength' && - attr.name !='size' && - attr.name !='class' && - attr.name !='start' && - attr.name !='tabIndex' && - attr.name !='style' && + attr.value != 'null' && + attr.value != 'auto' && + attr.value != 'false' && + attr.value != 'inherit' && + (attr.value != '0' || attr.name == 'value') && + attr.name != 'loop' && + attr.name != 'complete' && + attr.name != 'maxLength' && + attr.name != 'size' && + attr.name != 'class' && + attr.name != 'start' && + attr.name != 'tabIndex' && + attr.name != 'style' && attr.name.substr(0, 6) != 'jQuery') { // in IE we need to check for all of these. if (/ng\d+/.exec(attr.name) || @@ -220,7 +220,7 @@ function sortedHtml(element, showNgClass) { } for (var css in node.style) { var value = node.style[css]; - if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) { + if (isString(value) && isString(css) && css != 'cssText' && value && (1 * css != css)) { var text = lowercase(css + ': ' + value); if (value != 'false' && style.indexOf(text) == -1) { style.push(text); @@ -240,7 +240,7 @@ function sortedHtml(element, showNgClass) { } html += '>'; var children = node.childNodes; - for (var j=0; j'; diff --git a/test/ng/browserSpecs.js b/test/ng/browserSpecs.js index 7153b1645fde..f14596a42e52 100755 --- a/test/ng/browserSpecs.js +++ b/test/ng/browserSpecs.js @@ -337,7 +337,7 @@ describe('browser', function() { it('should log warnings when 4kb per cookie storage limit is reached', function() { var i, longVal = '', cookieStr; - for (i=0; i<4083; i++) { + for (i = 0; i < 4083; i++) { longVal += 'x'; } @@ -920,7 +920,7 @@ describe('browser', function() { }); } - describe('update $location when it was changed outside of Angular in sync '+ + describe('update $location when it was changed outside of Angular in sync ' + 'before $digest was called', function() { it('should work with no history support, no html5Mode', function() { diff --git a/test/ng/cacheFactorySpec.js b/test/ng/cacheFactorySpec.js index d704cf683e9a..7159484d68d4 100644 --- a/test/ng/cacheFactorySpec.js +++ b/test/ng/cacheFactorySpec.js @@ -181,7 +181,7 @@ describe('$cacheFactory', function() { var cache = $cacheFactory('cache1', {capacity: 5}); expect(cache.info().size).toBe(0); - for (var i=0; i<5; i++) { + for (var i = 0; i < 5; i++) { cache.put('id' + i, i); } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 4b3d67ad3f3a..9509e90b6202 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -275,7 +275,7 @@ describe('$compile', function() { })); // NOTE: This test may be redundant. - it('should handle custom svg containers that transclude to foreignObject'+ + it('should handle custom svg containers that transclude to foreignObject' + ' that transclude to custom svg containers that transclude to custom elements', inject(function() { element = jqLite('
                  ' + '' + @@ -300,7 +300,7 @@ describe('$compile', function() { })); - it('should support directives with SVG templates and a slow url '+ + it('should support directives with SVG templates and a slow url ' + 'that are stamped out later by a transcluding directive', function() { module(function() { directive('svgCircleUrl', valueFn({ @@ -355,8 +355,8 @@ describe('$compile', function() { it('should not wrap root whitespace text nodes in spans', function() { element = jqLite( - '
                  A
                  \n '+ // The spaces and newlines here should not get wrapped - '
                  B
                  C\t\n '+ // The "C", tabs and spaces here will be wrapped + '
                  A
                  \n ' + // The spaces and newlines here should not get wrapped + '
                  B
                  C\t\n ' + // The "C", tabs and spaces here will be wrapped '
                  '); $compile(element.contents())($rootScope); var spans = element.find('span'); @@ -1587,7 +1587,7 @@ describe('$compile', function() { expect(function() { $compile('
                  '); $httpBackend.flush(); - }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [async, sync] asking for template on: '+ + }).toThrowMinErr('$compile', 'multidir', 'Multiple directives [async, sync] asking for template on: ' + '
                  '); }); }); @@ -2979,8 +2979,8 @@ describe('$compile', function() { }); inject(function($compile, $rootScope) { - element = $compile('
                  '+ - ''+ + element = $compile('
                  ' + + '' + '
                  ')($rootScope); $rootScope.$apply(function() { @@ -3558,7 +3558,7 @@ describe('$compile', function() { function test(literalString, literalValue) { - compile('
                  '); + compile('
                  '); $rootScope.$apply(); expect(componentScope.reference).toBe(literalValue); @@ -4335,7 +4335,7 @@ describe('$compile', function() { expect(asyncCtrlSpy).not.toHaveBeenCalled(); $templateCache.put('myDirectiveAsync.html', '
                  Hello!
                  '); - element = $compile('
                  '+ + element = $compile('
                  ' + '' + '' + '
                  ')($rootScope); @@ -5147,7 +5147,7 @@ describe('$compile', function() { }, link: function(scope, el, attr, ctrl, $transclude) { var i; - for (i=0; i
                  ')($rootScope); var children = element.children(), i; - for (i=0; i'+ - ''+ - ''+ + '
                  ' + + '' + + '' + '
                  '); expect(function() { $compile(doc)(scope); diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 8d4e47763609..e7064a0259f2 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -1010,7 +1010,7 @@ describe('ngModel', function() { function createInput(type) { inject(function($compile, $rootScope) { scope = $rootScope; - inputElm = $compile('')($rootScope); + inputElm = $compile('')($rootScope); }); } @@ -1544,8 +1544,8 @@ describe('input', function() { it('should allow overriding the model update trigger event on text inputs', function() { compileInput( - ''); changeInputValueTo('a'); @@ -1556,8 +1556,8 @@ describe('input', function() { it('should not dirty the input if nothing was changed before updateOn trigger', function() { compileInput( - ''); browserTrigger(inputElm, 'blur'); @@ -1566,8 +1566,8 @@ describe('input', function() { it('should allow overriding the model update trigger event on text areas', function() { compileInput( - '