From a915c5c0acb53866f09215f25350ccf1f396ea3b Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Wed, 6 Jul 2016 09:44:49 +0000 Subject: [PATCH 1/5] add --quiet feature --- index.js | 4 +++- readme.md | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index d0941c08..b0aca23b 100644 --- a/index.js +++ b/index.js @@ -64,7 +64,9 @@ 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); + 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 From 335b333fb707dbfd55b2d63ac9a1d9347803ad9d Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Wed, 6 Jul 2016 19:01:32 +0000 Subject: [PATCH 2/5] tweaks and add test --- cli.js | 1 + index.js | 5 +++-- test/cli.js | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) 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 b0aca23b..1ec2d18c 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); - - return engine.executeOnText(str, opts.filename); + var report = engine.executeOnText(str, opts.filename); + report.results = opts.quiet ? eslint.CLIEngine.getErrorResults(report.results) : report.results; + return report; }; exports.lintFiles = function (patterns, opts) { diff --git a/test/cli.js b/test/cli.js index b9d1ae65..8bb97e48 100644 --- a/test/cli.js +++ b/test/cli.js @@ -37,3 +37,13 @@ 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'); + + try { + await execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath]); + } catch (err) { + t.true(err.stdout.indexOf('warning') === -1); + } +}); From ee3d28966c64797240519c55d813298066e356e2 Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Wed, 6 Jul 2016 19:38:20 +0000 Subject: [PATCH 3/5] tweaks --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1ec2d18c..5ad64a11 100644 --- a/index.js +++ b/index.js @@ -10,8 +10,8 @@ exports.lintText = function (str, opts) { var engine = new eslint.CLIEngine(opts); var report = engine.executeOnText(str, opts.filename); - report.results = opts.quiet ? eslint.CLIEngine.getErrorResults(report.results) : report.results; - return report; + + return processReport(report, opts); }; exports.lintFiles = function (patterns, opts) { @@ -66,6 +66,11 @@ function runEslint(paths, opts) { var config = optionsManager.buildConfig(opts); var engine = new eslint.CLIEngine(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; } From 286777a441b02f50821345095f500e55bee64a5f Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Thu, 7 Jul 2016 04:28:23 +0000 Subject: [PATCH 4/5] tweaks --- test/cli.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/cli.js b/test/cli.js index 8bb97e48..f2550c5d 100644 --- a/test/cli.js +++ b/test/cli.js @@ -40,10 +40,6 @@ test('supports being extended with a shareable config', async () => { test('quiet option', async t => { const filepath = await tempWrite('// TODO: quiet\nconsole.log()\n', 'x.js'); - - try { - await execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath]); - } catch (err) { - t.true(err.stdout.indexOf('warning') === -1); - } + var err = await t.throws(execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath])); + t.is(err.stdout.indexOf('warning'), -1); }); From 392d6626c001e9e0d8ccdbad6f491929e35f16fb Mon Sep 17 00:00:00 2001 From: Chintan Radia Date: Thu, 7 Jul 2016 16:27:35 +0530 Subject: [PATCH 5/5] tweaks --- test/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cli.js b/test/cli.js index f2550c5d..34126fa9 100644 --- a/test/cli.js +++ b/test/cli.js @@ -40,6 +40,6 @@ test('supports being extended with a shareable config', async () => { test('quiet option', async t => { const filepath = await tempWrite('// TODO: quiet\nconsole.log()\n', 'x.js'); - var err = await t.throws(execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath])); + const err = await t.throws(execa('../cli.js', ['--no-local', '--quiet', '--reporter=compact', filepath])); t.is(err.stdout.indexOf('warning'), -1); });