node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org »

grunt-jshint-extended

grunt-jshint-extended

Repository for grunt-jshint-extended - a grunt plug-in to have some extended options over grunt-contrib-jshint plug-in. It provides you different custom tasks to validate your JS files which enable developers to have more freedom like:

  • Validating all JS files at once will not generate a single report rather it will generate separate reports for each file with their names at configured path. This will be more structured than a single file.
  • Other benefits includes that we can validate only specific JS lines of code in a given JS file and not the whole JS file. These options can be helpful for existing projects where we need to validate only new/specific code and not the whole JS.

Please read more about available tasks below.

Getting Started

This package requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-jshint-extended --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-jshint-extended');

And add to your task list using jshintextended:

grunt.registerTask('default', ['jshintextended']);

The "jshintextended" task

Overview

In your project's Gruntfile, add a section named jshintextended to the data object passed into grunt.initConfig().

Task jshintextended accept any setting which works with grunt-contrib-jshint plug-in. Catch here is that you have to provide one extra Object in jshint options object with name jshintExtraOpts, please see below example:

jshintextended: {
    all: ['js/**/*.js', '!js/plugins/**/*.js'],
    options: {
        // This will generate the report in HTML format. 
        reporter: require('jshint-html-reporter'),
        // JS Validation rules are configured in .jshintrc file. 
        jshintrc: '.jshintrc',
        // This is the extra Object which needs to be set with 'jshint' options. 
        jshintExtraOpts: {
            errorReportDir: "js_errors/",
            removeTempFile: true
        }
    }
}

Note: For other standard JSHINT options please refer to grunt-contrib-jshint

Options

options.jshintExtraOpts

Type: Object
Default value: { errorReportDir: "js/errors/", removeTempFile: false // This Property stands true only for custom helper task "validatejslines". }

Object to define the extra settings over original jshint plug-in which will be used by this plug-in. Please read below about each setting.

options.jshintExtraOpts.errorReportDir

Type: String
Default value: js_errors/ Directory Path where JS error reports will be generated in form of HTML with JS file names.

options.jshintExtraOpts.removeTempFile

Type: Boolean
Default value: 'true' Setting it false will not delete the temp JS file from root folder. This property works only with validatejslines custom task.

Tasks Available

validatejslines

Running 'validatejslines' task by grunt validatejslines command will validate only Lines of Code for provided one JS file in prompted Input Textbox with rules mentioned in '.jshintrc' file. This task will Prompt developer to provide JS file name with relative path to your root directory followed by line ranges to be validated.

For example you have a js file with path 'js/test.js' and you want to validate lines 1-5 and 15-18 from this file then provide below data into prompted textbox. You can provide as many as line ranges separated by a space.

  js/test.js 1-5 15-18

validatejs

Running 'validatejs' task by grunt validatejs command will validate only JS files provided in prompted Input Textbox with rules mentioned in '.jshintrc' file. This task will Prompt developer to provide JS file names with relative path to your root directory in a Textbox and then same will be validated to generate the report.

For example if you want to validate multiple js files then provide those JS file names in below format. Please note that file names should be provided with relative path to your root directory and multiple file names should be provided separated by space.

  js/test.js js/test1.js js/test2.js js/test3.js

validateselectedjs

Running 'validateselectedjs' task by grunt validateselectedjs command will validate only JS files selected by user from a list of JS files with rules mentioned in '.jshintrc' file. This task will Prompt developer to select JS file names in form of Checkbxes and files list will be generated by files configured in JSHINT option with variable 'jsFilesToBeValidated'. Selection of files can be made by Space 'key' and then can be run by 'return' key.

validatealljs

Running 'validatealljs' task by grunt validatealljs command will validate all the JS files with rules mentioned in '.jshintrc' file. This will validate all the JS files configured in JSHINT task option with variable 'jsFilesToBeValidated'.

Release History

  • 2016-02-27 v0.0.9 Updated peer dependency to support Grunt 1.0.0
  • 2016-02-27 v0.0.8 Fixed the code to support on latest Node/NPM version.
  • 2016-02-26 v0.0.7 Updated Peer Dependency
  • 2015-11-26 v0.0.6 Fixed some Typo.
  • 2015-11-26 v0.0.5 Updated the plug-in for fixing directory path on windows OS.
  • 2015-05-10 v0.0.4 Updated the plug-in for fixing the issue where it was not able to load "grunt-contrib-jshint and grunt-prompt" from the local plug-in directory. Now its working fine for all the custom tasks provided by plug-in.
  • 2015-05-10 v0.0.3 Updated Package.json.
  • 2015-05-10 v0.0.2 Fixed issues where plug-in was not able to load the dependencies and custom tasks.
  • 2015-05-09 v0.0.1 Published the Plug-in with first version.