From 2fd46f1a81b2120336e13be72112a7a9d6338d2b Mon Sep 17 00:00:00 2001 From: Joel Kemp Date: Mon, 3 Nov 2014 20:38:53 -0500 Subject: [PATCH] Used JSCS and fixed violations --- .jscsrc | 3 ++ Gruntfile.js | 8 ++++++ package.json | 3 +- tasks/lib/livereload.js | 2 +- tasks/lib/taskrun.js | 2 +- tasks/lib/taskrunner.js | 2 +- test/tasks/events_test.js | 52 +++++++++++++++++++++++------------ test/tasks/helper.js | 2 +- test/tasks/livereload_test.js | 33 ++++++++++++++-------- test/tasks/patterns_test.js | 6 ++-- test/tasks/watch_test.js | 8 ++++-- 11 files changed, 83 insertions(+), 38 deletions(-) create mode 100644 .jscsrc diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..60a4d21 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,3 @@ +{ + "preset": "grunt" +} \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 7241343..afca163 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,6 +20,12 @@ module.exports = function(grunt) { jshintrc: '.jshintrc', }, }, + jscs: { + src: ['tasks/**/*.js', 'test/tasks/**/*.js'], + options: { + config: '.jscsrc' + } + }, watch: { all: { files: ['<%= jshint.all %>'], @@ -34,6 +40,7 @@ module.exports = function(grunt) { // Dynamic alias task to nodeunit. Run individual tests with: grunt test:events grunt.registerTask('test', function(file) { grunt.task.run('jshint'); + grunt.task.run('jscs'); grunt.config('nodeunit.tests', String(grunt.config('nodeunit.tests')).replace('*', file || '*')); grunt.task.run('nodeunit'); }); @@ -43,6 +50,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-internal'); + grunt.loadNpmTasks('grunt-jscs'); grunt.registerTask('default', ['test', 'build-contrib']); }; diff --git a/package.json b/package.json index c99a3f2..9aedb86 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,8 @@ "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-nodeunit": "~0.4.1", "grunt-contrib-internal": "~0.4.7", - "underscore.string": "~2.3.3" + "underscore.string": "~2.3.3", + "grunt-jscs": "~1.0.0" }, "peerDependencies": { "grunt": "~0.4.0" diff --git a/tasks/lib/livereload.js b/tasks/lib/livereload.js index 5e8ab04..6750228 100644 --- a/tasks/lib/livereload.js +++ b/tasks/lib/livereload.js @@ -16,7 +16,7 @@ var servers = Object.create(null); module.exports = function(grunt) { - var defaults = { port: 35729 }; + var defaults = {port: 35729}; function LR(options) { if (options === true) { diff --git a/tasks/lib/taskrun.js b/tasks/lib/taskrun.js index 9025f19..822fc14 100644 --- a/tasks/lib/taskrun.js +++ b/tasks/lib/taskrun.js @@ -32,7 +32,7 @@ module.exports = function(grunt) { } } - var getErrorCount = function(){ + var getErrorCount = function() { if (typeof grunt.fail.forever_warncount !== 'undefined') { return grunt.fail.forever_warncount + grunt.fail.forever_errorcount; } else { diff --git a/tasks/lib/taskrunner.js b/tasks/lib/taskrunner.js index 78f3391..17bbb50 100644 --- a/tasks/lib/taskrunner.js +++ b/tasks/lib/taskrunner.js @@ -61,7 +61,7 @@ module.exports = function(grunt) { // Normalize cwd option if (typeof self.options.cwd === 'string') { - self.options.cwd = { files: self.options.cwd, spawn: self.options.cwd }; + self.options.cwd = {files: self.options.cwd, spawn: self.options.cwd}; } // Function to call when closing the task diff --git a/test/tasks/events_test.js b/test/tasks/events_test.js index c04a2ae..fabf318 100644 --- a/test/tasks/events_test.js +++ b/test/tasks/events_test.js @@ -44,9 +44,12 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added'); - test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event not emitted when file changed'); - test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event not emitted when file deleted'); + test.ok(result.indexOf('lib/added.js was indeed added') !== -1, + 'event not emitted when file added'); + test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, + 'event not emitted when file changed'); + test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, + 'event not emitted when file deleted'); test.done(); }); }, @@ -59,9 +62,12 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event not emitted when file added'); - test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed'); - test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted'); + test.ok(result.indexOf('lib/added.js was indeed added') !== -1, + 'event not emitted when file added'); + test.ok(result.indexOf('lib/one.js was indeed changed') === -1, + 'event should NOT have emitted when file changed'); + test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, + 'event should NOT have emitted when file deleted'); test.done(); }); }, @@ -74,9 +80,12 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added'); - test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, 'event should have emitted when file changed'); - test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, 'event should NOT have emitted when file deleted'); + test.ok(result.indexOf('lib/added.js was indeed added') === -1, + 'event should NOT have emitted when file added'); + test.ok(result.indexOf('lib/one.js was indeed changed') !== -1, + 'event should have emitted when file changed'); + test.ok(result.indexOf('lib/added.js was indeed deleted') === -1, + 'event should NOT have emitted when file deleted'); test.done(); }); }, @@ -89,9 +98,12 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/added.js was indeed added') === -1, 'event should NOT have emitted when file added'); - test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed'); - test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted'); + test.ok(result.indexOf('lib/added.js was indeed added') === -1, + 'event should NOT have emitted when file added'); + test.ok(result.indexOf('lib/one.js was indeed changed') === -1, + 'event should NOT have emitted when file changed'); + test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, + 'event should have emitted when file deleted'); test.done(); }); }, @@ -104,9 +116,13 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/added.js was indeed added') !== -1, 'event should have emitted when file added'); - test.ok(result.indexOf('lib/one.js was indeed changed') === -1, 'event should NOT have emitted when file changed'); - test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, 'event should have emitted when file deleted'); + test.ok(result.indexOf('lib/added.js was indeed added') !== -1, + 'event should have emitted when file added'); + test.ok(result.indexOf('lib/one.js was indeed changed') === -1, + 'event should NOT have emitted when file changed'); + test.ok(result.indexOf('lib/added.js was indeed deleted') !== -1, + + 'event should have emitted when file deleted'); test.done(); }); }, @@ -125,8 +141,10 @@ exports.events = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('lib/one/test.js was indeed changed\ntargetOne specifc event was fired') !== -1, 'event should have been emitted with targetOne specified'); - test.ok(result.indexOf('lib/two/test.js was indeed changed\ntargetTwo specifc event was fired') !== -1, 'event should have been emitted with targetTwo specified'); + test.ok(result.indexOf('lib/one/test.js was indeed changed\ntargetOne specifc event was fired') !== -1, + 'event should have been emitted with targetOne specified'); + test.ok(result.indexOf('lib/two/test.js was indeed changed\ntargetTwo specifc event was fired') !== -1, + 'event should have been emitted with targetTwo specified'); test.done(); }); }, diff --git a/test/tasks/helper.js b/test/tasks/helper.js index 0a1f422..84dd5fc 100644 --- a/test/tasks/helper.js +++ b/test/tasks/helper.js @@ -90,7 +90,7 @@ helper.assertTask = function assertTask(task, options) { // clean up files within fixtures helper.cleanUp = function cleanUp(files) { - if (typeof files === 'string') files = [files]; + if (typeof files === 'string') { files = [files]; } files.forEach(function(filepath) { filepath = path.join(helper.fixtures, filepath); if (grunt.file.exists(filepath)) { diff --git a/test/tasks/livereload_test.js b/test/tasks/livereload_test.js index 8beb82c..c1c83ad 100644 --- a/test/tasks/livereload_test.js +++ b/test/tasks/livereload_test.js @@ -56,7 +56,8 @@ exports.livereload = { result = helper.unixify(result); helper.verboseLog(result); test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.'); - test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.'); + test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, + 'live reload server should have been started on port 35729.'); test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js'); resultData = JSON.parse(resultData); test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); @@ -77,7 +78,8 @@ exports.livereload = { result = helper.unixify(result); helper.verboseLog(result); test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.'); - test.ok(result.indexOf('Live reload server started on port: 8675') !== -1, 'live reload server should have been started on port 35729.'); + test.ok(result.indexOf('Live reload server started on port: 8675') !== -1, + 'live reload server should have been started on port 35729.'); test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js'); resultData = JSON.parse(resultData); test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); @@ -97,7 +99,8 @@ exports.livereload = { helper.verboseLog(result); test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js'); test.ok(result.indexOf('Live reloading lib/two.js...') !== -1, 'live reload should have triggered on lib/two.js'); - test.ok(!/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have cleared js file that was already reloaded'); + test.ok(!/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), + 'live reload should have cleared js file that was already reloaded'); test.done(); }); }, @@ -116,8 +119,10 @@ exports.livereload = { result = helper.unixify(result); helper.verboseLog(result); test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.'); - test.ok(result.indexOf('Live reload server started on port: 9876') !== -1, 'live reload server should have been started on port 9876.'); - test.ok(/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), 'live reload should have triggered on lib/one.js and lib/two.js'); + test.ok(result.indexOf('Live reload server started on port: 9876') !== -1, + 'live reload server should have been started on port 9876.'); + test.ok(/Live reloading (lib\/one\.js, lib\/two.js|lib\/two.js, lib\/one.js)\.\.\./.test(result), + 'live reload should have triggered on lib/one.js and lib/two.js'); resultData = JSON.parse(resultData); test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); test.done(); @@ -137,7 +142,8 @@ exports.livereload = { result = helper.unixify(result); helper.verboseLog(result); test.ok(result.indexOf('I ran before livereload.') !== -1, 'task should have ran before live reload.'); - test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, 'live reload server should have been started on port 1337.'); + test.ok(result.indexOf('Live reload server started on port: 1337') !== -1, + 'live reload server should have been started on port 1337.'); test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js'); resultData = JSON.parse(resultData); test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); @@ -157,7 +163,8 @@ exports.livereload = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, 'live reload server should have been started on port 35729.'); + test.ok(result.indexOf('Live reload server started on port: 35729') !== -1, + 'live reload server should have been started on port 35729.'); test.ok(result.indexOf('Live reloading lib/one.js...') !== -1, 'live reload should have triggered on lib/one.js'); resultData = JSON.parse(resultData); test.equal(resultData.tinylr, 'Welcome', 'tinylr server should have welcomed you.'); @@ -175,8 +182,10 @@ exports.livereload = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('Live reloading sass/one.scss') === -1, 'Should not trigger live reload on non livereload targets.'); - test.ok(result.indexOf('Live reloading css/one.css') !== -1, 'Should trigger live reload when other tasks trigger livereload targets.'); + test.ok(result.indexOf('Live reloading sass/one.scss') === -1, + 'Should not trigger live reload on non livereload targets.'); + test.ok(result.indexOf('Live reloading css/one.css') !== -1, + 'Should trigger live reload when other tasks trigger livereload targets.'); test.done(); }); }, @@ -206,7 +215,8 @@ exports.livereload = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('Live reloading lib/one.js...') === -1, 'Should not livereload when a task errors with flag'); + test.ok(result.indexOf('Live reloading lib/one.js...') === -1, + 'Should not livereload when a task errors with flag'); test.done(); }); }, @@ -221,7 +231,8 @@ exports.livereload = { }], function(result) { result = helper.unixify(result); helper.verboseLog(result); - test.ok(result.indexOf('Live reloading lib/one.js...') === -1, 'Should not livereload when a task errors with flag and spawn=false'); + test.ok(result.indexOf('Live reloading lib/one.js...') === -1, + 'Should not livereload when a task errors with flag and spawn=false'); test.done(); }); }, diff --git a/test/tasks/patterns_test.js b/test/tasks/patterns_test.js index afc359f..5f42b13 100644 --- a/test/tasks/patterns_test.js +++ b/test/tasks/patterns_test.js @@ -34,8 +34,10 @@ exports.patterns = { }, 3000); }, function(result) { helper.verboseLog(result); - test.ok(result.indexOf('File "lib' + path.sep + 'edit.js" changed') !== -1, 'Watch should have been triggered when edit.js was edited.'); - test.ok(result.indexOf('File "lib' + path.sep + 'dontedit.js" changed') === -1, 'Watch should NOT have been triggered when dontedit.js was edited.'); + test.ok(result.indexOf('File "lib' + path.sep + 'edit.js" changed') !== -1, + 'Watch should have been triggered when edit.js was edited.'); + test.ok(result.indexOf('File "lib' + path.sep + 'dontedit.js" changed') === -1, + 'Watch should NOT have been triggered when dontedit.js was edited.'); test.done(); }); }, diff --git a/test/tasks/watch_test.js b/test/tasks/watch_test.js index 0672f1c..82bb8cf 100644 --- a/test/tasks/watch_test.js +++ b/test/tasks/watch_test.js @@ -45,7 +45,7 @@ exports.watch = { var cwd = path.resolve(fixtures, 'dateFormat'); var assertWatch = helper.assertTask(['watch', '--debug'], {cwd:cwd}); assertWatch(function() { - grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;'); + grunt.file.write(path.join(cwd, 'lib', 'one.js'), 'var one = true;'); }, function(result) { helper.verboseLog(result); test.ok(result.indexOf('dateFormat has worked!') !== -1, 'Should have displayed a custom dateFormat.'); @@ -61,7 +61,8 @@ exports.watch = { grunt.file.write(path.join(cwd, 'lib', 'one.js'), write); }, function(result) { helper.verboseLog(result); - test.ok(result.indexOf('File "lib' + path.sep + 'one.js" changed') !== -1, 'Watch should have fired when oneTarget/lib/one.js has changed.'); + test.ok(result.indexOf('File "lib' + path.sep + 'one.js" changed') !== -1, + 'Watch should have fired when oneTarget/lib/one.js has changed.'); test.ok(result.indexOf('I do absolutely nothing.') !== -1, 'echo task should have fired.'); test.done(); }); @@ -141,7 +142,8 @@ exports.watch = { var interruptMatches = result.match(/have been interrupted/g); test.ok(interruptMatches && interruptMatches.length === 2, 'Task should have been interrupted 2 times.'); var unInterruptMatches = result.match(/I want to be interrupted/g); - test.ok(unInterruptMatches && unInterruptMatches.length === 1, 'Only the last time should be working (without interruption)'); + test.ok(unInterruptMatches && unInterruptMatches.length === 1, + 'Only the last time should be working (without interruption)'); test.done(); }); },