Skip to content

Commit

Permalink
Merge pull request #11761 from twbs/jscs
Browse files Browse the repository at this point in the history
add JavaScript Code Style checker integration
  • Loading branch information
mdo committed Dec 7, 2013
2 parents 4be126e + c1dae1e commit b441632
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
20 changes: 18 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* jshint node: true */

module.exports = function(grunt) {
module.exports = function (grunt) {
"use strict";

// Force use of Unix newlines
Expand Down Expand Up @@ -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 %>',
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
14 changes: 14 additions & 0 deletions js/.jscs.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down
2 changes: 1 addition & 1 deletion js/tests/unit/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>'
Expand Down
6 changes: 3 additions & 3 deletions js/tests/unit/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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")
Expand Down Expand Up @@ -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')
})

Expand Down
2 changes: 1 addition & 1 deletion js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

1 comment on commit b441632

@zlatanvasovic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it would be nice to deprecate leading commas in objects (like JSON).

Please sign in to comment.