diff --git a/cli.js b/cli.js index be327ef5..a7853ff8 100755 --- a/cli.js +++ b/cli.js @@ -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', diff --git a/index.js b/index.js index d0941c08..5ad64a11 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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; diff --git a/readme.md b/readme.md index fd630890..db3fa46e 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/test/cli.js b/test/cli.js index b9d1ae65..34126fa9 100644 --- a/test/cli.js +++ b/test/cli.js @@ -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); +});