Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # mocha-eslint Changelog

### 2.1.0
* [ENHANCEMENT] Support Mocha `slow` override option
* [ENHANCEMENT] Add `strict` option to treat warnings as failures
### 2.0.2

@@ -7,0 +11,0 @@ * [BUGFIX] Prevent duplicate error messages when more than one file with errors

32

index.js

@@ -16,2 +16,6 @@ var CLIEngine = require('eslint').CLIEngine;

if (opts && opts.slow) {
this.slow(opts.slow);
}
if (opts && opts.formatter) {

@@ -30,17 +34,15 @@ format = opts.formatter;

if (
report &&
report.errorCount > 0
) {
throw new Error(
chalk.red('Code did not pass lint rules') +
// remove process.cwd() to convert absolute to relative paths
replaceAll(process.cwd() + '/', '', formatter(report.results))
);
} else if (
warn &&
report &&
report.warningCount > 0
) {
console.log(formatter(report.results));
if (report) {
if (report.errorCount > 0 || (opts.strict && report.warningCount > 0)) {
throw new Error(
chalk.red('Code did not pass lint rules') +
// remove process.cwd() to convert absolute to relative paths
replaceAll(process.cwd() + '/', '', formatter(report.results))
);
} else if (
warn &&
report.warningCount > 0
) {
console.log(formatter(report.results));
}
}

@@ -47,0 +49,0 @@

{
"name": "mocha-eslint",
"version": "2.0.2",
"version": "2.1.0",
"description": "run ESLint as mocha tests",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -6,5 +6,5 @@ # mocha-eslint

A simple way to run [ESLint](http://eslint.org/) in your
[Mocha](http://mochajs.org/) tests without a task runner like Grunt or Gulp.
A simple way to run [ESLint](http://eslint.org/) in your [Mocha](http://mochajs.org/) tests without a task runner like Grunt or Gulp.
Inspired by [mocha-jshint](https://github.com/Muscula/mocha-jshint) from

@@ -15,16 +15,16 @@ [Allan Ebdrup](https://github.com/Muscula).

You can install into your node.js project as a development dependency with:
You can install into your Node.js project as a development dependency with:
```sh
npm install --save-dev mocha-eslint
```
$ 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.
`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.
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](http://eslint.org/docs/user-guide/migrating-to-1.0.0) 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:
Mocha and requiring `mocha-eslint` like so:
```javascript

@@ -37,13 +37,12 @@ var lint = require('mocha-eslint');

```
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](https://github.com/isaacs/node-glob#glob-primer))
and `options` has a single property `"formatter"` which can be assigned to the
name of any of the
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](https://github.com/isaacs/node-glob#glob-primer)) and `options`
has a single property `formatter` that can be assigned to the name of any of the
[ESLint formatters](https://github.com/eslint/eslint/tree/master/lib/formatters)
("stylish" (the default), "compact", "checkstyle", "jslint-xml", "junit" and
"tap") or the full path to a JavaScript file containing a custom formatter. If
(`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:
```javascript

@@ -62,12 +61,19 @@ var lint = require('mocha-eslint');

// Specify style of output
var options = {};
options.formatter = 'compact';
var options = {
// Specify style of output
formatter: 'compact', // Defaults to `stylish`
// Only display warnings if a test is failing
options.alwaysWarn = false; // Defaults to true, always show warnings
// 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
options.timeout = 5000; // Defaults to the global mocha timeout option
// 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
};
// Run the tests

@@ -79,3 +85,4 @@ 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. As of version 1.0.0, no rules are enabled by default.
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.

@@ -82,0 +89,0 @@ [npm-image]: https://img.shields.io/npm/v/mocha-eslint.svg

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