From e35be731cc90a50e6d27b4d7409988f72707de57 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 1 Nov 2015 10:11:36 -0500 Subject: [PATCH] Adding JSCS integration --- .jscsrc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 20 +++++----------- config.js | 9 ++++++- gulpfile.js | 38 +++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 .jscsrc diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..ba4e2cf --- /dev/null +++ b/.jscsrc @@ -0,0 +1,68 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "case", + "return", + "try", + "typeof" + ], + "requireSpaceBeforeBlockStatements": true, + "requireParenthesesAroundIIFE": true, + "requireSpacesInConditionalExpression": true, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "requireSpaceBetweenArguments": true, + "requireMultipleVarDecl": "onevar", + "requireVarDeclFirst": true, + "requireBlocksOnNewline": true, + "disallowEmptyBlocks": true, + "disallowSpacesInsideArrayBrackets": true, + "disallowSpacesInsideParentheses": true, + "requireCommaBeforeLineBreak": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforePostfixUnaryOperators": true, + "disallowSpaceBeforeBinaryOperators": [ + "," + ], + "requireSpacesInForStatement": true, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceAfterBinaryOperators": true, + "disallowKeywords": [ + "with", + "continue" + ], + "validateIndentation": 2, + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowTrailingComma": true, + "disallowKeywordsOnNewLine": [ + "else" + ], + "requireLineFeedAtFileEnd": true, + "requireCapitalizedConstructors": true, + "requireDotNotation": true, + "disallowNewlineBeforeBlockStatements": true, + "disallowMultipleLineStrings": true, + "requireSpaceBeforeObjectValues": true +} diff --git a/README.md b/README.md index 8064f14..de661a7 100644 --- a/README.md +++ b/README.md @@ -22,21 +22,13 @@ There are several gulp tasks available to build various parts of the site, but t This will build the site into the ./build directory, start a local start on port 8080, and begin watching the source files for modifications. The site will automatically be rebuilt when files are changed. Also, if you browser has the LiveReload extension, then the page will be reloaded. -To automatically run Karma test, run the following: +These other gulp tasks are available: - $ gulp karma - -To build the site for deployment, run the following: - - $ gulp build - -The site will be built into the ./build directory. - -To build developer documentation, run the following: - - $ gulp docs - -The documentation will be build into the ./docs directory. + $ gulp docs # Build documentation into the ./docs directory + $ gulp build # Build the site into the ./build directory + $ gulp verify # Run JSCS lint and Karma tests + $ gulp verify:watch # Run JSCS lint and Karma tests when files change + $ gulp lint:fix # Automatically fix some lint errors ## License diff --git a/config.js b/config.js index 43177a5..b9a6158 100644 --- a/config.js +++ b/config.js @@ -15,8 +15,15 @@ module.exports = { sass: './src/**/*.scss', svg_sass: './src/sass/svg.scss', js: ['./src/**/*.js', './src/**/*.peg'], - spec: './spec/**/*_spec.js' + spec: './spec/**/*_spec.js', + lint: [ + './lib/**/*.js', + './src/**/*.js', + './spec/**/*.js', + './*.js' + ] }, + lintRoots: ['lib', 'src', 'spec'], browserify: { debug: true, fullPaths: false, diff --git a/gulpfile.js b/gulpfile.js index 2ecbb50..a3a0752 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -137,6 +137,10 @@ gulp.task('scripts', function() { .pipe(gulp.dest(config.buildPath('js'))); }); +gulp.task('verify', ['karma:single', 'lint']); + +gulp.task('verify:watch', ['karma', 'lint:watch']); + gulp.task('karma', function(done) { var karma = require('karma'), path = require('path'), @@ -157,3 +161,37 @@ gulp.task('karma:single', function(done) { server.start(); }); + +gulp.task('lint', function() { + var jscs = require('gulp-jscs'); + + return gulp.src(config.globs.lint) + .pipe(jscs()) + .pipe(jscs.reporter()) + .pipe(jscs.reporter('fail')) + .on('error', notify.onError()) +}); + +gulp.task('lint:watch', function() { + gulp.watch(config.globs.lint, ['lint']); +}); + +gulp.task('lint:fix', config.lintRoots.map(function(root) { + return 'lint:fix:' + root; +}), function() { + var jscs = require('gulp-jscs'); + + return gulp.src('./*.js') + .pipe(jscs({fix: true})) + .pipe(gulp.dest('.')); +}); + +config.lintRoots.forEach(function(root) { + gulp.task('lint:fix:' + root, function() { + var jscs = require('gulp-jscs'); + + return gulp.src('./' + root + '/**/*.js') + .pipe(jscs({fix: true})) + .pipe(gulp.dest('./' + root)); + }); +}); diff --git a/package.json b/package.json index 5f62269..a29cf1e 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "gulp-docco": "0.0.4", "gulp-front-matter": "^1.3.0", "gulp-hb": "^2.6.5", + "gulp-jscs": "^3.0.2", "gulp-notify": "^2.0.1", "gulp-rename": "^1.2.2", "gulp-sass": "^2.1.0",