Skip to content

Commit

Permalink
add --quiet feature (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfreaker authored and sindresorhus committed Jul 7, 2016
1 parent b6199c0 commit bb76a2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var cli = meow({
' --plugin Include third-party plugins [Can be set multiple times]',
' --extend Extend defaults with a custom config [Can be set multiple times]',
' --open Open files with issues in your editor',
' --quiet Show only errors and no warnings',
'',
'Examples',
' $ xo',
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ exports.lintText = function (str, opts) {
opts = optionsManager.buildConfig(opts);

var engine = new eslint.CLIEngine(opts);
var report = engine.executeOnText(str, opts.filename);

return engine.executeOnText(str, opts.filename);
return processReport(report, opts);
};

exports.lintFiles = function (patterns, opts) {
Expand Down Expand Up @@ -64,7 +65,14 @@ function mergeReports(reports) {
function runEslint(paths, opts) {
var config = optionsManager.buildConfig(opts);
var engine = new eslint.CLIEngine(config);
return engine.executeOnFiles(paths, config);
var report = engine.executeOnFiles(paths, config);

return processReport(report, opts);
}

function processReport(report, opts) {
report.results = opts.quiet ? eslint.CLIEngine.getErrorResults(report.results) : report.results;
return report;
}

exports.getFormatter = eslint.CLIEngine.getFormatter;
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $ xo --help
--plugin Include third-party plugins [Can be set multiple times]
--extend Extend defaults with a custom config [Can be set multiple times]
--open Open files with issues in your editor
--quiet Show only errors and no warnings
Examples
$ xo
Expand Down
6 changes: 6 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ test('supports being extended with a shareable config', async () => {
const cwd = path.join(__dirname, 'fixtures/project');
await execa('../../../cli.js', ['--no-local'], {cwd});
});

test('quiet option', async t => {
const filepath = await tempWrite('// TODO: quiet\nconsole.log()\n', 'x.js');
const err = await t.throws(execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath]));
t.is(err.stdout.indexOf('warning'), -1);
});

0 comments on commit bb76a2d

Please sign in to comment.