You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

simplebuild-jshint

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplebuild-jshint

A simple library for automating JSHint

0.3.0
Source
npm
Version published
Maintainers
1
Created
Source

Simplebuild-JSHint

A simple library for automating JSHint.

JSHint is a static analysis ("lint") tool for JavaScript. It analyzes JavaScript source code for common mistakes. This library provides a simple interface to JSHint that's convenient to use with task automation tools such as Grunt or Jake.

Installation

This is a Node.js library. Install Node, then:

npm install simplebuild-jshint (add --save or --save-dev if you want)

Note that this library uses your existing JSHint installation. (JSHint will be installed if needed.)

Usage

This library provides these functions:

  • checkFiles: Run JSHint against a list of files.
  • checkOneFile: Run JSHint against a single file (it's useful for auto-generated build dependencies).
  • checkCode: Run JSHint against raw source code.

checkFiles(options, success, failure)

Run JSHint against a list of files. A dot will be written to stdout for each file processed. Any errors will be written to stdout.

  • options: an object containing the following properties:

    • files: a string or array containing the files to check. Globs (*) and globstars (**) will be expanded to match files and directory trees respectively. Prepend ! to exclude files.
    • options (optional): JSHint options (see the JSHint documentation.
    • globals (optional): Permitted global variables (for use with the undef option). Each variable should be set to true or false. If false, the variable is considered read-only.
  • success(): a function to call if the code validates successfully.

  • failure(message): a function to call if the code does not validate successfully. A simple error message is provided in the message parameter, but detailed error messages are written to stdout.

checkOneFile(options, success, failure)

Run JSHint against a single file (it's useful for auto-generated build dependencies).

  • options: an object containing the following properties:

    • file: a string containing the path to the file to check.
    • options (optional): JSHint options (see the JSHint documentation.
    • globals (optional): Permitted global variables (for use with the undef option). Each variable should be set to true or false. If false, the variable is considered read-only.
  • success(): a function to call if the code validates successfully.

  • failure(message): a function to call if the code does not validate successfully. A simple error message is provided in the message parameter, but detailed error messages are written to stdout.

checkCode(options, success, failure)

Run JSHint against raw source code. Any errors will be written to stdout.

  • options: an object containing the following properties:

    • code: a string containing the source code to check.
    • options (optional): JSHint options (see the JSHint documentation.
    • globals (optional): Permitted global variables (for use with the undef option). Each variable should be set to true or false. If false, the variable is considered read-only.
  • success() a function to call if the code validates successfully.

  • failure(message) a function to call if the code does not validate successfully. A simple error message is provided in the message parameter, but detailed error messages are output to stdout.

Examples

This library is designed to be easy to integrate with any task automation tool:

Grunt

var jshint = require("simplebuild-jshint");

module.exports = function(grunt) {
    grunt.initConfig({
        jshint: {
            files: [ "*.js", "src/**/*.js", "test/**/*.js" ],
            options: {
                bitwise: true,
                curly: false,
                eqeqeq: true
                // etc
            }
        }
    });

    grunt.registerTask("lint", "Lint everything", function() {
        jshint.checkFiles(grunt.config("jshint"), this.async(), grunt.warn);
    });

    grunt.registerTask("default", [ "lint" ]);
};

Jake

var jshint = require("simplebuild-jshint");

task("default", [ "lint" ]);

task("lint", function() {
    jshint.checkFiles({
        files: [ "*.js", "src/**/*.js", "test/**/*.js" ],
        options: {
            bitwise: true,
            curly: false,
            eqeqeq: true
            // etc
        }
    }, complete, fail);
}, { async: true });

Plain JavaScript

var jshint = require("simplebuild-jshint");

jshint.checkFiles({
    files: [ "*.js", "src/**/*.js", "test/**/*.js" ],
    options: {
        bitwise: true,
        curly: false,
        eqeqeq: true
        // etc
    }
}, function() {
    console.log("OK");
}, function(message) {
    console.log(message);
});

About Simplebuild

This library is a simplebuild module. In addition to being used as a standalone library (as described above), it can also be used with simplebuild extensions and mappers. For more information about simplebuild, see the Simplebuild GitHub page.

Version History

0.3.0: Added jshint as a peer dependency. It no longer needs to be installed separately.

0.2.0: checkOneFile().

0.1.1: Corrected documentation error: options.globals is not actually a JSHint option.

0.1.0: checkSource() and checkFiles().

License

The MIT License (MIT)

Copyright (c) 2012-2014 James Shore

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

simplebuild

FAQs

Package last updated on 29 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts