Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocha-jshint

Package Overview
Dependencies
Maintainers
7
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-jshint

run JSHint as mocha tests

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9K
increased by89.53%
Maintainers
7
Weekly downloads
 
Created
Source

mocha-jshint npm version Build Status Dependency Status devDependency Status

Run jshint as Mocha tests.

To install in your node.js project as devDependency, run this command, in the root of your project

npm install mocha-jshint --save-dev

usage

Mocha defaults to looking for your test specs in the test folder of your project. Add this file as test/jshint.spec.js in your project, with the following content:

require('mocha-jshint')();

That is it you are done.

To grep only the jshint test, just do

mocha --grep jshint

using with git

If you are using git as version control you can do the following in your test:

require('mocha-jshint')({
	git: {
		modified: true,
		commits: 2
	}
});

This means that jshint will only lint the files that are modified on disk according to git, and the files modified in the last two git commits.

There is also the masterDiff option:

require('mocha-jshint')({
	git: {
		modified: true,
		commits: 2,
		masterDiff:true
	}
});

This means that if we are on any other branch than master, only the files changed compared to the master branch will be linted.

If we are on the master branch, only the files that are modified on disk according to git, and the files modified in the last two git commits will be linted.

specifying paths

Normally I would recommend configuring what to lint with .jshintingore described in configuring jshint. And just lint the working directory.

But if you want to specify specific paths to lint, you can do the following in your test:

require('mocha-jshint')({
	paths: [
		'/some/path/',
		'/some/other/path'
	]
});

Each path may be either a file path or a directory path, and should yield a valid file or directory when passed through path.resolve(). Each path listed in the array will be linted on a separate test.

changing test suite name

The default name for the test suite generated by mocha-jshint is jshint, but it may be overridden in the following manner:

require('mocha-jshint')({
	title: 'My custom test suite name'
});

configuring jshint

In the root of your project you can add a .jshintignore file, where each line is a file or directory for jshint to ignore and not check for errors. (see this project for an example)

At the root of your project you can add a .jshintrc file, that specifies what options you want jshint to run with (see this project for an example)

You can also add a .jshintrc file to any subdirectory of your project, to override the .jshintrc settings in the root. For example in this project I allow some global variables in the test folder. Global variables that are set when I run mocha tests. Global variables that are only allowed to be used, in the .js files in the test folder

Why?

This module was created to:

  • Make adding jshint testing to a project using Mocha as easy as possible
  • Make it easy to piggyback on all the different Mocha reporters (dot, spec, teamcity etc) for jshint output
  • Make sure that you get a click-able link directly to the problem in WebStorm, when jshint fails
  • Make sure that there is no unnecessary noise in the test output

Version history

2.2: Added paths and title options.

2.1: Added git masterDiff option.

2.0: Added git features. Removed old undocumented paths feature.

License

MIT

Keywords

FAQs

Package last updated on 23 Apr 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc