run ESLint as mocha tests
npm install mocha-eslintA simple way to run ESLint in your
Mocha tests without a task runner like Grunt or Gulp.
Inspired by mocha-jshint from
Allan Ebdrup.
You can install into your Node.js project as a development dependency with:
``sh`
npm install --save-dev mocha-eslintmocha-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.
After mocha-eslint is installed, you can use it by creating a test file for
Mocha and requiring mocha-eslint like so:`javascript`
var lint = require('mocha-eslint');`
This will return a function with the signature:javascript`
lint(paths, options)paths
where is an array of paths from your project's top level directory (asoptions
of v0.1.2, you can also include
glob patterns) and formatter
has a single property that can be assigned to the name of any of thestylish
ESLint formatters
( (the default), compact, checkstyle, jslint-xml, junit andtap) or the full path to a JavaScript file containing a custom formatter. Ifoptions is not included, the default "stylish" formatter will be used.
So, a full test file to run in Mocha might look like:
`javascript
var lint = require('mocha-eslint');
// Array of paths to lint
// Note: a seperate Mocha test will be run for each path and each file which
// matches a glob pattern
var paths = [
'bin',
'lib',
'tests/*/Test.js',
'!tests/NotATest.js', // negation also works
];
var options = {
// Specify style of output
formatter: 'compact', // Defaults to stylish
// Only display warnings if a test is failing
alwaysWarn: false, // Defaults to true, always show warnings
// Increase the timeout of the test if linting takes to long
timeout: 5000, // Defaults to the global mocha timeout option
// Increase the time until a test is marked as slow
slow: 1000, // Defaults to the global mocha slow option
// Consider linting warnings as errors and return failure
strict: true, // Defaults to false, only notify the warnings
// Specify the mocha context in which to run tests
contextName: 'eslint', // Defaults to eslint, but can be any string
};
// Run the tests
lint(paths, options);
`
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.
[npm-image]: https://img.shields.io/npm/v/mocha-eslint.svg
[npm-url]: https://www.npmjs.com/package/mocha-eslint
[dependency-image]: https://david-dm.org/BadgeLabs/mocha-eslint.svg
[dependency-rul]: https://david-dm.org/BadgeLabs/mocha-eslint
[travis-image]: https://travis-ci.org/BadgeLabs/mocha-eslint.svg?branch=master
[travis-url]: https://travis-ci.org/BadgeLabs/mocha-eslint