jshint-globals

0.1.0 • Public • Published

jshint-globals

Use predefined jshint globals.

Problem

If you have many Javascript projects and need to define jshint globals and use them in a grunt task e.g. grunt-contrib-jshint. There should be a much easier way to reuse these globals between projects. And there should be an option to download already pre-defined globals.

Solution

With jshint-globals you can easily use predefined or reuse you old globals. Install jshint-globals:

npm install jshint-globals --save-dev

Just require jshint-globals:

var jshintGlobals = require('jshint-globals');

insert into the globals properties in your grunt-contrib-jshint task option:

jshint : {
  options : {
    globals : jshintGlobals({
      variable1 : true,
      variable2 : true,
      nestedVariables : {
        nestedVariable1 : true,
        nestedVariable2 : true
      }
    })
  }
}

the above equals:

jshint : {
  options : {
    globals : {
      variable1 : true,
      variable2 : true,
      nestedVariable1 : true,
      nestedVariable2 : true
    }
  }
}

Use array instead of object:

jshint : {
  options : {
    globals : jshintGlobals([
      'variable1',
      'variable2',
      {
        nestedObjectVariable1 : true,
        nestedObjectVariable2 : true
      },
      ['nestedArrayVariable1', 'nestedArrayVariable1']
    })
  }
}

the above equals:

jshint : {
  options : {
    globals : {
      variable1 : true,
      variable2 : true,
      nestedObjectVariable1 : true,
      nestedObjectVariable2 : true,
      nestedArrayVariable1 : true,
      nestedArrayVariable2 : true
    }
  }
}

Use pre-defined globals

var jshintGlobals = require('jshint-globals');
var browser = jshintGlobals.browser;
 
...
 
jshint : {
  options : {
    globals : jshintGlobals({
      variable1 : true,
      variable2 : true,
      browser : browser
    })
  }
}

the above equals:

jshint : {
  options : {
    globals : {
      variable1 : true,
      variable2 : true,
      open : true,
      document : true,
      navigator : true,
      ...
    }
  }
}

Available globals

var browser = require('jshint-globals').browser;
var _requirejs = require('jshint-globals').requirejs;
var mocha = require('jshint-globals').mocha

Please check the source for all globals defined in each category

Readme

Keywords

none

Package Sidebar

Install

npm i jshint-globals

Weekly Downloads

4

Version

0.1.0

License

MIT

Last publish

Collaborators

  • tinganho