Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --quiet feature #131

Merged
merged 5 commits into from
Jul 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new processReport(report, opts) function that contains this common code:

function processReport(report, opts) {
  report.results = ....
  return report;
}

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);
});