# mocha-jshint

> run JSHint as mocha tests

Latest version **2.3.1** (published 2016-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocha-jshint
pnpm add mocha-jshint
yarn add mocha-jshint
bun add mocha-jshint
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2016-02-07 |
| First published | 2013-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | Allan Ebdrup |
| Maintainers | ebdrup, bifrost, eagleeye, kapetan, wtfil, bubenshchykov, mpushkin, jonatanpedersen, fizker |
| Keywords | mocha, jshint |

## Links

- npm: https://www.npmjs.com/package/mocha-jshint
- Repository: https://github.com/ebdrup/mocha-jshint
- Issues: https://github.com/ebdrup/mocha-jshint/issues
- npm.io page: https://npm.io/package/mocha-jshint

## Dependencies (4)

- [uniq](https://npm.io/package/uniq.md) ^1.0.1
- [jshint](https://npm.io/package/jshint.md) ^2.8.0
- [shelljs](https://npm.io/package/shelljs.md) ^0.4.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.0

## Recent versions

- 2.3.1 (latest) — 2016-02-07
- 2.3.0 — 2016-01-29
- 2.2.6 — 2016-01-07
- 2.2.5 — 2015-10-13
- 2.2.4 — 2015-10-13
- 2.2.3 — 2015-05-05
- 2.2.2 — 2015-04-25
- 2.2.1 — 2015-04-24
- 2.2.0 — 2015-04-23
- 2.1.1 — 2015-04-17
- 2.1.0 — 2015-04-17
- 2.0.2 — 2015-04-17
- 2.0.1 — 2015-04-17
- 2.0.0 — 2015-04-17
- 1.1.0 — 2015-04-14
- … 10 more at https://npm.io/package/mocha-jshint/versions

## README

mocha-jshint [![npm version](https://badge.fury.io/js/mocha-jshint.svg)](http://badge.fury.io/js/mocha-jshint) [![Build Status](https://travis-ci.org/ebdrup/mocha-jshint.svg?branch=master)](https://travis-ci.org/ebdrup/mocha-jshint) [![Dependency Status](https://david-dm.org/ebdrup/mocha-jshint.svg)](https://david-dm.org/ebdrup/mocha-jshint) [![devDependency Status](https://david-dm.org/ebdrup/mocha-jshint/dev-status.svg)](https://david-dm.org/ebdrup/mocha-jshint#info=devDependencies)
------------

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:

```js
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:
```js
require('mocha-jshint')({
	git: {
		modified: true,
		commits: 2,
		exec: {
			maxBuffer: 20*1024*1024
		}
	}
});
```
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:
```js
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 `.jshintignore` described in 
[configuring jshint](https://github.com/ebdrup/mocha-jshint#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:
```js
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:
```js
require('mocha-jshint')({
	title: 'My custom test suite name'
});
```


pretty output
-------------
For pretty-printed output, with errors grouped by filename, enable the `pretty` option:
```js
require('mocha-jshint')({
	pretty: true
});
```

Sample output:
```
$ npm test
  1) jshint should pass for working directory:
      Found 3 jshint error(s) in 2 file(s):
           /tmp/abc.js
                    1:1     Missing semicolon. (W033)
                   18:0     Identifier 'good_times' is not in camel case. (W106)

           /tmp/xyz.js
                    3:5     '_' is defined but never used. (W098)
```

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

---
_Source: https://npm.io/package/mocha-jshint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
