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

mocha-eslint

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-eslint

run ESLint as mocha tests

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
increased by167.1%
Maintainers
1
Weekly downloads
 
Created
Source

mocha-eslint

Travis Build Status Dependency Status NPM version

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.

Note: verison 1.0.0 of this project uses eslint 1.0.0. Read the migration guide to learn what you need to do for the upgrade, but the main thing is that ESLint will no longer provide rules by default, you'll need to set them explicitly or extend from a shared config.

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" which 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');

// 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
];

// Specify style of output
var options = {};
options.formatter = 'compact';

// Only display warnings if a test is failing
options.alwaysWarn = false; // Defaults to true, always show warnings

// Increase the timeout of the test if linting takes to long
options.timeout = 5000; // Defaults to the global mocha timeout option

// Run the tests
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. As of version 1.0.0, no rules are enabled by default.

Keywords

FAQs

Package last updated on 15 Mar 2016

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