Skip to content

Commit ae62873

Browse files
committed
Adds JSCS for gulpfile and scripts
install JSCS globally npm install jscs -g use `npm run jscs`
1 parent 2b39b64 commit ae62873

File tree

5 files changed

+162
-59
lines changed

5 files changed

+162
-59
lines changed

.jscsrc

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"requireCurlyBraces": [
3+
"if",
4+
"else",
5+
"for",
6+
"while",
7+
"do",
8+
"try",
9+
"catch"
10+
],
11+
"requireOperatorBeforeLineBreak": true,
12+
"requireCamelCaseOrUpperCaseIdentifiers": true,
13+
"maximumLineLength": {
14+
"value": 80,
15+
"allowComments": true,
16+
"allowRegex": true
17+
},
18+
"validateIndentation": 2,
19+
"validateQuoteMarks": "'",
20+
"disallowMultipleLineStrings": true,
21+
"disallowMixedSpacesAndTabs": true,
22+
"disallowTrailingWhitespace": true,
23+
"disallowSpaceAfterPrefixUnaryOperators": true,
24+
"disallowMultipleVarDecl": true,
25+
"disallowKeywordsOnNewLine": [
26+
"else"
27+
],
28+
"requireSpaceAfterKeywords": [
29+
"if",
30+
"else",
31+
"for",
32+
"while",
33+
"do",
34+
"switch",
35+
"return",
36+
"try",
37+
"catch"
38+
],
39+
"requireSpaceBeforeBinaryOperators": [
40+
"=",
41+
"+=",
42+
"-=",
43+
"*=",
44+
"/=",
45+
"%=",
46+
"<<=",
47+
">>=",
48+
">>>=",
49+
"&=",
50+
"|=",
51+
"^=",
52+
"+=",
53+
"+",
54+
"-",
55+
"*",
56+
"/",
57+
"%",
58+
"<<",
59+
">>",
60+
">>>",
61+
"&",
62+
"|",
63+
"^",
64+
"&&",
65+
"||",
66+
"===",
67+
"==",
68+
">=",
69+
"<=",
70+
"<",
71+
">",
72+
"!=",
73+
"!=="
74+
],
75+
"requireSpaceAfterBinaryOperators": true,
76+
"requireSpacesInConditionalExpression": true,
77+
"requireSpaceBeforeBlockStatements": true,
78+
"requireSpacesInForStatement": true,
79+
"requireLineFeedAtFileEnd": true,
80+
"requireSpacesInFunctionExpression": {
81+
"beforeOpeningCurlyBrace": true
82+
},
83+
"disallowSpacesInAnonymousFunctionExpression": {
84+
"beforeOpeningRoundBrace": true
85+
},
86+
"disallowSpacesInsideObjectBrackets": "all",
87+
"disallowSpacesInsideArrayBrackets": "all",
88+
"disallowSpacesInsideParentheses": true,
89+
"validateJSDoc": {
90+
"checkParamNames": true,
91+
"requireParamTypes": true
92+
},
93+
"disallowMultipleLineBreaks": true,
94+
"disallowNewlineBeforeBlockStatements": true
95+
}

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ php:
66
- 5.5
77
- 5.4
88
before_install:
9-
- npm install -g bower
9+
- npm install -g bower gulp jscs
1010
- npm install
1111
script:
1212
- npm run build
1313
- npm run jshint
14+
- npm run jscs

assets/scripts/main.js

+54-49
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,66 @@
1616

1717
(function($) {
1818

19-
// Use this variable to set up the common and page specific functions. If you
20-
// rename this variable, you will also need to rename the namespace below.
21-
var Sage = {
22-
// All pages
23-
common: {
24-
init: function() {
25-
// JavaScript to be fired on all pages
19+
// Use this variable to set up the common and page specific functions. If you
20+
// rename this variable, you will also need to rename the namespace below.
21+
var Sage = {
22+
// All pages
23+
'common': {
24+
init: function() {
25+
// JavaScript to be fired on all pages
26+
},
27+
finalize: function() {
28+
// JavaScript to be fired on all pages, after page specific JS is fired
29+
}
2630
},
27-
finalize: function() {
28-
// JavaScript to be fired on all pages, after page specific JS is fired
29-
}
30-
},
31-
// Home page
32-
home: {
33-
init: function() {
34-
// JavaScript to be fired on the home page
31+
// Home page
32+
'home': {
33+
init: function() {
34+
// JavaScript to be fired on the home page
35+
},
36+
finalize: function() {
37+
// JavaScript to be fired on the home page, after the init JS
38+
}
3539
},
36-
finalize: function() {
37-
// JavaScript to be fired on the home page, after the init JS
38-
}
39-
},
40-
// About us page, note the change from about-us to about_us.
41-
about_us: {
42-
init: function() {
43-
// JavaScript to be fired on the about us page
40+
// About us page, note the change from about-us to about_us.
41+
'about_us': {
42+
init: function() {
43+
// JavaScript to be fired on the about us page
44+
}
4445
}
45-
}
46-
};
46+
};
4747

48-
// The routing fires all common scripts, followed by the page specific scripts.
49-
// Add additional events for more control over timing e.g. a finalize event
50-
var UTIL = {
51-
fire: function(func, funcname, args) {
52-
var namespace = Sage;
53-
funcname = (funcname === undefined) ? 'init' : funcname;
54-
if (func !== '' && namespace[func] && typeof namespace[func][funcname] === 'function') {
55-
namespace[func][funcname](args);
56-
}
57-
},
58-
loadEvents: function() {
59-
// Fire common init JS
60-
UTIL.fire('common');
48+
// The routing fires all common scripts, followed by the page specific scripts.
49+
// Add additional events for more control over timing e.g. a finalize event
50+
var UTIL = {
51+
fire: function(func, funcname, args) {
52+
var fire;
53+
var namespace = Sage;
54+
funcname = (funcname === undefined) ? 'init' : funcname;
55+
fire = func !== '';
56+
fire = fire && namespace[func];
57+
fire = fire && typeof namespace[func][funcname] === 'function';
6158

62-
// Fire page-specific init JS, and then finalize JS
63-
$.each(document.body.className.replace(/-/g, '_').split(/\s+/),function(i,classnm) {
64-
UTIL.fire(classnm);
65-
UTIL.fire(classnm, 'finalize');
66-
});
59+
if (fire) {
60+
namespace[func][funcname](args);
61+
}
62+
},
63+
loadEvents: function() {
64+
// Fire common init JS
65+
UTIL.fire('common');
66+
67+
// Fire page-specific init JS, and then finalize JS
68+
$.each(document.body.className.replace(/-/g, '_').split(/\s+/), function(i, classnm) {
69+
UTIL.fire(classnm);
70+
UTIL.fire(classnm, 'finalize');
71+
});
6772

68-
// Fire common finalize JS
69-
UTIL.fire('common', 'finalize');
70-
}
71-
};
73+
// Fire common finalize JS
74+
UTIL.fire('common', 'finalize');
75+
}
76+
};
7277

73-
// Load Events
74-
$(document).ready(UTIL.loadEvents);
78+
// Load Events
79+
$(document).ready(UTIL.loadEvents);
7580

7681
})(jQuery); // Fully reference jQuery after this point.

gulpfile.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var project = manifest.getProjectGlobs();
1515
var cssTasks = function(filename) {
1616
return lazypipe()
1717
.pipe($.plumber)
18-
.pipe(function () {
18+
.pipe(function() {
1919
return $.if(mapsEnabled, $.sourcemaps.init());
2020
})
2121
.pipe(function() {
@@ -35,11 +35,12 @@ var cssTasks = function(filename) {
3535
.pipe($.pleeease, {
3636
autoprefixer: {
3737
browsers: [
38-
'last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4', 'opera 12'
38+
'last 2 versions', 'ie 8', 'ie 9', 'android 2.3', 'android 4',
39+
'opera 12'
3940
]
4041
}
4142
})
42-
.pipe(function () {
43+
.pipe(function() {
4344
return $.if(mapsEnabled, $.sourcemaps.write('.'));
4445
})
4546
.pipe(gulp.dest, path.dist + 'styles')
@@ -48,7 +49,7 @@ var cssTasks = function(filename) {
4849

4950
gulp.task('styles', function() {
5051
var merged = merge();
51-
manifest.forEachDependency('css', function (dep) {
52+
manifest.forEachDependency('css', function(dep) {
5253
merged.add(gulp.src(dep.globs)
5354
.pipe(cssTasks(dep.name)));
5455
});
@@ -67,14 +68,14 @@ gulp.task('jshint', function() {
6768
var jsTasks = function(filename) {
6869
var fn = filename;
6970
return lazypipe()
70-
.pipe(function () {
71+
.pipe(function() {
7172
return $.if(mapsEnabled, $.sourcemaps.init());
7273
})
7374
.pipe(function() {
7475
return $.if(!!fn, $.concat(fn || 'all.js'));
7576
})
7677
.pipe($.uglify)
77-
.pipe(function () {
78+
.pipe(function() {
7879
return $.if(mapsEnabled, $.sourcemaps.write('.'));
7980
})
8081
.pipe(gulp.dest, path.dist + 'scripts')
@@ -83,7 +84,7 @@ var jsTasks = function(filename) {
8384

8485
gulp.task('scripts', ['jshint'], function() {
8586
var merged = merge();
86-
manifest.forEachDependency('js', function (dep) {
87+
manifest.forEachDependency('js', function(dep) {
8788
merged.add(gulp.src(dep.globs)
8889
.pipe(jsTasks(dep.name)));
8990
});
@@ -106,7 +107,7 @@ gulp.task('images', function() {
106107
});
107108

108109
gulp.task('version', function() {
109-
return gulp.src([path.dist + '**/*.{js,css}'], { base: path.dist })
110+
return gulp.src([path.dist + '**/*.{js,css}'], {base: path.dist})
110111
.pipe(gulp.dest(path.dist))
111112
.pipe($.rev())
112113
.pipe(gulp.dest(path.dist))

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
],
1919
"scripts": {
2020
"build": "bower install && gulp",
21-
"jshint": "gulp jshint"
21+
"jshint": "gulp jshint",
22+
"jscs": "jscs gulpfile.js assets/scripts/*.js"
2223
},
2324
"engines": {
2425
"node": ">= 0.10.0"

0 commit comments

Comments
 (0)