mocha-eslint
A simple way to run ESLint in your
Mocha tests without a task runner like Grunt or Gulp.
Inspired by mocha-jshint from
Allan Ebdrup.
Installation
You can install into your Node.js project as a development dependency with:
npm install --save-dev mocha-eslint
mocha-eslint
will install ESLint for itself, so you don't need to worry about
adding it to your consuming module.
The same is not true for Mocha. You should already have Mocha installed in your
consuming module.
Usage
After mocha-eslint is installed, you can use it by creating a test file for
Mocha and requiring mocha-eslint
like so:
var lint = require('mocha-eslint');
This will return a function with the signature:
lint(paths, options)
where paths
is an array of paths from your project's top level directory (as
of v0.1.2, you can also include
glob patterns) and options
has a single property formatter
that can be assigned to the name of any of the
ESLint formatters
(stylish
(the default), compact
, checkstyle
, jslint-xml
, junit
and
tap
) or the full path to a JavaScript file containing a custom formatter. If
options
is not included, the default "stylish" formatter will be used.
So, a full test file to run in Mocha might look like:
var lint = require('mocha-eslint');
var paths = [
'bin',
'lib',
'tests/**/*Test.js',
'!tests/NotATest.js',
];
var options = {
formatter: 'compact',
alwaysWarn: false,
timeout: 5000,
slow: 1000,
strict: true
};
lint(paths, options);
Notes
This module does not make any decisions about which ESLint rules to run. Make
sure your project has a .eslintrc
file if you want ESLint to do anything.