diff --git a/Gruntfile.js b/Gruntfile.js index 00c11340..1a79d71c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -37,6 +37,18 @@ module.exports = function(grunt) { }, files: ['package.json'] }, + jshint: { + all: [ + '*.js', + 'lib/**/*.js', + 'plugins/**/*.js', + 'templates/**/*.js' + ], + options: { + ignores: ['templates/default/static/scripts/prettify/*'], + jshintrc: '.jshintrc' + } + }, shell: { 'coverage': { command: './node_modules/.bin/istanbul cover <%= nodeBin %> -- -T', @@ -78,7 +90,7 @@ module.exports = function(grunt) { grunt.registerTask('test-rhino', ['shell:test-rhino']); grunt.registerTask('test-rhino-esprima', ['shell:test-rhino-esprima']); grunt.registerTask('test-node', ['shell:test-node']); - grunt.registerTask('test', ['test-rhino', 'test-rhino-esprima', 'test-node']); + grunt.registerTask('test', ['test-rhino', 'test-rhino-esprima', 'test-node', 'jshint']); grunt.registerTask('default', ['test']); }; diff --git a/package.json b/package.json index 9b6a3f5d..3995ea5d 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "devDependencies": { "grunt": "~0.4.2", "grunt-bumpup": "~0.4.2", + "grunt-contrib-jshint": "~0.8.0", "grunt-shell": "~0.6.1", "istanbul": "~0.2.1", - "jshint": "~2.3.0", "load-grunt-tasks": "~0.2.1", "tv4": "git+https://github.com/hegemonic/tv4.git#own-properties" }, diff --git a/templates/default/static/scripts/linenumber.js b/templates/default/static/scripts/linenumber.js index 34611ed0..8d52f7ea 100644 --- a/templates/default/static/scripts/linenumber.js +++ b/templates/default/static/scripts/linenumber.js @@ -1,3 +1,4 @@ +/*global document */ (function() { var source = document.getElementsByClassName('prettyprint source linenums'); var i = 0; diff --git a/test/specs/jshint/jshint-clean.js b/test/specs/jshint/jshint-clean.js deleted file mode 100644 index 0d7a8a04..00000000 --- a/test/specs/jshint/jshint-clean.js +++ /dev/null @@ -1,80 +0,0 @@ -/*global app: true, beforeEach: true, describe: true, env: true, expect: true, it: true */ -var async = require('async'); -var fs = require('jsdoc/fs'); -var path = require('jsdoc/path'); - -var config = JSON.parse( fs.readFileSync( path.join(env.dirname, '.jshintrc'), 'utf8' ) ); - -var jsHintCheck; - -describe('jshint-clean', function() { - // Only run JSHint on Node.js, because a) we only need to lint everything once and b) the - // current version of JSHint is really slow on Rhino - if ( !require('jsdoc/util/runtime').isNode() ) { - return; - } - - jsHintCheck = function(filename, callback) { - var JSHINT = require('jshint').JSHINT; - var jsHintErrors; - - fs.readFile(filename, 'utf8', function(err, data) { - if (err) { - callback(err); - } else { - JSHINT(data, config); - if (JSHINT.errors.length) { - jsHintErrors = filename + ' is not JSHint clean: ' + JSON.stringify(JSHINT.errors); - } - - callback(null, jsHintErrors); - } - }); - }; - - it('should generate JSHint errors for bad code', function(done) { - var file = path.join(env.dirname, 'test', 'fixtures', 'jshint', 'badfile.js'); - - jsHintCheck(file, function(err, jsHintErrors) { - expect(err).toBeFalsy(); - expect(jsHintErrors).toBeDefined(); - done(); - }); - }); - - it('should not generate JSHint errors for good code', function(done) { - var file = path.join(env.dirname, 'test', 'fixtures', 'jshint', 'goodfile.js'); - - jsHintCheck(file, function(err, jsHintErrors) { - expect(err).toBeFalsy(); - expect(jsHintErrors).toBeUndefined(); - done(); - }); - }); - - it('should not find JSHint errors in JSDoc', function(done) { - var files, - filter, - source; - - // check all .js files unless they're tests; rhino shim files that probably can't be - // delinted; or third-party modules - source = { - includePattern: '.+[\\|/]lib[\\|/].+\\.js$|.+[\\|/]plugins[\\|/]\\w+\\.js$', - excludePattern: '.+[\\|/]test[\\|/].+|.+[\\|/]node_modules[\\|/].+|.+[\\|/]Jake[\\|/].+' - }; - filter = new (require('jsdoc/src/filter').Filter)(source); - - files = app.jsdoc.scanner.scan([env.dirname], 10, filter); - - async.forEach(files, function(file, cb) { - jsHintCheck(file, function(err, jsHintErrors) { - expect(jsHintErrors).toBeUndefined(); - cb(err); - }); - }, function(err) { - expect(err).toBeFalsy(); - done(); - }); - }); -});