Skip to content

Commit

Permalink
Add quiet mode via --quiet flag
Browse files Browse the repository at this point in the history
The implementation exactly matches how ESLint handles this
behavior in their CLI.
  • Loading branch information
Evan Jacobs committed May 30, 2016
1 parent a0d3c0d commit b203e9c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ npm install eslintify
browserify your_file.js -t eslintify
```

### "quiet" mode

Functionally equivalent to the [ESLint CLI](http://eslint.org/docs/user-guide/command-line-interface) flag `--quiet`: it causes warnings to be silently ignored. The default is for warnings to be outputted along with errors.

```bash
browserify your_file.js -t [ eslintify --quiet ]
```

### "continuous" mode

If you wish to get linting reports in the console but not break the build, enable "continuous mode" like so:
Expand Down
30 changes: 22 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
var eslint = require('eslint');
var through = require('through');
var error = console.error.bind(console);
var default_formatter = require.resolve('eslint-friendly-formatter');

function hasCount(result) {
return result.errorCount || result.warningCount;
}

function lint(file, options) {
options = options || {};
options.formatter = options.formatter || default_formatter;

var cli = new eslint.CLIEngine(options);
var formatter = cli.getFormatter(options.formatter || require.resolve('eslint-friendly-formatter'));
var formatter = cli.getFormatter(options.formatter);
var data = '';

function write(buf) {
Expand All @@ -16,13 +22,16 @@ function lint(file, options) {
function end() {
var results = cli.executeOnText(data, file).results;

if (results.length && results.some(function (r) { return r.errorCount || r.warningCount; })) {
if (options.quiet) {
results = eslint.CLIEngine.getErrorResults(results);
} // filter out warnings

if (results.length && results.some(hasCount)) {
error(formatter(results));
}

var errorResults = eslint.CLIEngine.getErrorResults(results);
if (errorResults.length && !options.continuous) {
this.emit('error', 'eslintify: linting error(s) detected.');
if (!options.continuous) {
this.emit('error', 'eslintify: linting error(s) detected.');
}
}

this.queue(data);
Expand All @@ -36,8 +45,13 @@ function lint(file, options) {
var givenExtension = file.slice(file.lastIndexOf('.') + 1, file.length);
var supportedExtensions = ['js', 'jsx', 'es6'];

if (options.extension) { supportedExtensions = supportedExtensions.concat(options.extension); }
if (options.extensions) { supportedExtensions = supportedExtensions.concat(options.extensions); }
if (options.extension) {
supportedExtensions = supportedExtensions.concat(options.extension);
}

if (options.extensions) {
supportedExtensions = supportedExtensions.concat(options.extensions);
}

if (supportedExtensions.indexOf(givenExtension) !== -1) {
return through(write, end);
Expand Down

0 comments on commit b203e9c

Please sign in to comment.