diff --git a/Gruntfile.js b/Gruntfile.js index c60e600ab8..4e713d7c85 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,6 +1,6 @@ /* jshint node: true */ -module.exports = function(grunt) { +module.exports = function (grunt) { "use strict"; // Force use of Unix newlines @@ -40,6 +40,21 @@ module.exports = function(grunt) { } }, + jscs: { + options: { + config: 'js/.jscs.json', + }, + gruntfile: { + src: ['Gruntfile.js'] + }, + src: { + src: ['js/*.js'] + }, + test: { + src: ['js/tests/unit/*.js'] + } + }, + concat: { options: { banner: '<%= banner %><%= jqueryCheck %>', @@ -288,6 +303,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-html-validation'); grunt.loadNpmTasks('grunt-jekyll'); + grunt.loadNpmTasks('grunt-jscs-checker'); grunt.loadNpmTasks('grunt-recess'); grunt.loadNpmTasks('grunt-saucelabs'); grunt.loadNpmTasks('grunt-sed'); @@ -296,7 +312,7 @@ module.exports = function(grunt) { grunt.registerTask('validate-html', ['jekyll', 'validation']); // Test task. - var testSubtasks = ['dist-css', 'jshint', 'qunit', 'validate-html']; + var testSubtasks = ['dist-css', 'jshint', 'jscs', 'qunit', 'validate-html']; // Only run Sauce Labs tests if there's a Sauce access key if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined') { testSubtasks.push('connect'); diff --git a/js/.jscs.json b/js/.jscs.json new file mode 100644 index 0000000000..2f04d9cd61 --- /dev/null +++ b/js/.jscs.json @@ -0,0 +1,14 @@ +{ + "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return"], + "requireSpacesInFunctionExpression": { "beforeOpeningCurlyBrace": true }, + "disallowLeftStickedOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], + "requireRightStickedOperators": ["!"], + "disallowRightStickedOperators": ["?", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], + "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], + "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], + "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], + "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], + "disallowKeywords": ["with"], + "validateLineBreaks": "LF", + "requireLineFeedAtFileEnd": true +} diff --git a/js/dropdown.js b/js/dropdown.js index 13352ef7cf..b84d219bd2 100644 --- a/js/dropdown.js +++ b/js/dropdown.js @@ -85,7 +85,7 @@ if (e.keyCode == 38 && index > 0) index-- // up if (e.keyCode == 40 && index < $items.length - 1) index++ // down - if (!~index) index=0 + if (!~index) index = 0 $items.eq(index).focus() } diff --git a/js/modal.js b/js/modal.js index 3ead5ee88b..5544cf04e0 100644 --- a/js/modal.js +++ b/js/modal.js @@ -180,7 +180,7 @@ } else if (!this.isShown && this.$backdrop) { this.$backdrop.removeClass('in') - $.support.transition && this.$element.hasClass('fade')? + $.support.transition && this.$element.hasClass('fade') ? this.$backdrop .one($.support.transition.end, callback) .emulateTransitionEnd(150) : diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 06219a1c8d..1b546a5799 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -19,7 +19,7 @@ $(function () { test("should switch active class on scroll", function () { var sectionHTML = '
' , $section = $(sectionHTML).append('#qunit-fixture') - , topbarHTML ='