aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2013-12-06 19:33:53 -0800
committerMark Otto <[email protected]>2013-12-06 19:33:53 -0800
commitb441632db143e5deb729b5d7109ad73b5e4e73d6 (patch)
tree365f373ec274f446c7f11a6442ed6995adb98e93
parent4be126e0142556805b59cb5a62d33c4a3fd2b8d4 (diff)
parentc1dae1e13c0dd5c53aa39b6aa6af8e07e4d3037f (diff)
downloadbootstrap-b441632db143e5deb729b5d7109ad73b5e4e73d6.tar.xz
bootstrap-b441632db143e5deb729b5d7109ad73b5e4e73d6.zip
Merge pull request #11761 from twbs/jscs
add JavaScript Code Style checker integration
-rw-r--r--Gruntfile.js20
-rw-r--r--js/.jscs.json14
-rw-r--r--js/dropdown.js2
-rw-r--r--js/modal.js2
-rw-r--r--js/tests/unit/scrollspy.js2
-rw-r--r--js/tests/unit/tooltip.js6
-rw-r--r--js/tooltip.js2
-rw-r--r--package.json1
8 files changed, 40 insertions, 9 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index c60e600ab..4e713d7c8 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 000000000..2f04d9cd6
--- /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 13352ef7c..b84d219bd 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 3ead5ee88..5544cf04e 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 06219a1c8..1b546a579 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 = '<div id="masthead"></div>'
, $section = $(sectionHTML).append('#qunit-fixture')
- , topbarHTML ='<div class="topbar">'
+ , topbarHTML = '<div class="topbar">'
+ '<div class="topbar-inner">'
+ '<div class="container">'
+ '<h3><a href="#">Bootstrap</a></h3>'
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 2139dc811..cc559ccb6 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -290,7 +290,7 @@ $(function () {
test("should place tooltips inside the body", function () {
var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>')
.appendTo('#qunit-fixture')
- .tooltip({container:'body'})
+ .tooltip({container: 'body'})
.tooltip('show')
ok($("body > .tooltip").length, 'inside the body')
ok(!$("#qunit-fixture > .tooltip").length, 'not found in parent')
@@ -301,7 +301,7 @@ $(function () {
var container = $("<div />").appendTo("body")
.css({position: "absolute", width: 200, height: 200, bottom: 0, left: 0})
, tooltip = $("<a href='#' title='Very very very very very very very very long tooltip'>Hover me</a>")
- .css({position: "absolute", top:0, left: 0})
+ .css({position: "absolute", top: 0, left: 0})
.appendTo(container)
.tooltip({placement: "top", animate: false})
.tooltip("show")
@@ -347,7 +347,7 @@ $(function () {
.tooltip('show')
, tooltip = container.find(".tooltip")
- ok( Math.round(target.offset().top + target[0].offsetHeight/2 - tooltip[0].offsetHeight/2) === Math.round(tooltip.offset().top) )
+ ok( Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) === Math.round(tooltip.offset().top) )
target.tooltip('hide')
})
diff --git a/js/tooltip.js b/js/tooltip.js
index 8debad96b..d3bf41fb2 100644
--- a/js/tooltip.js
+++ b/js/tooltip.js
@@ -133,7 +133,7 @@
}
Tooltip.prototype.show = function () {
- var e = $.Event('show.bs.'+ this.type)
+ var e = $.Event('show.bs.' + this.type)
if (this.hasContent() && this.enabled) {
this.$element.trigger(e)
diff --git a/package.json b/package.json
index 813cf1d13..3c9fd7fe6 100644
--- a/package.json
+++ b/package.json
@@ -32,6 +32,7 @@
, "grunt-contrib-watch": "~0.5.3"
, "grunt-html-validation": "~0.1.6"
, "grunt-jekyll": "~0.4.0"
+ , "grunt-jscs-checker": "~0.2.5"
, "grunt-recess": "~0.5.0"
, "grunt-saucelabs": "~4.1.2"
, "grunt-sed": "~0.1.1"