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 option #55

Merged
merged 3 commits into from
Sep 3, 2018
Merged
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function init() {
.description('Linter for Solidity programming language')
.action(execMainAction);

program
.usage('[options] <file> [...other_files]')
.option('-q, --quiet', 'report errors only - default: false')
Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplicating the previous block. I think you just need to add the .option line in that block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, I will modify it.

.action(execMainAction);

program
.command('stdin')
.description('linting of source code data provided to STDIN')
Expand All @@ -39,6 +44,12 @@ function execMainAction() {
const reportLists = program.args.filter(_.isString).map(processPath);
const reports =_.flatten(reportLists);

if (program.quiet) {
console.log('::::Quiet mode enabled - filtering out warnings::::');
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that we should log anything here.

// Setting int the report list errors only.
reports[0].reports = getErrorResults(reports);
}

printReports(reports, program.formatter);
exitWithCode(reports);
}
Expand Down Expand Up @@ -113,6 +124,17 @@ function processPath(path) {
return linter.processPath(path, readConfig());
}


/**
* Returns results that only contains errors.
* @param {LintResult[]} reporter The results to filter.
* @returns {LintResult[]} The filtered results.
**/
function getErrorResults(reporter) {
const reporterErrors = reporter[0].reports.filter(i => i.severity === 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is short and unlikely to be reused, I would do it inline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, its a good observation.

return reporterErrors;
}

function printReports(reports, formatter) {
const formatterName = formatter || 'stylish';
const formatterFn = require(`eslint/lib/formatters/${formatterName}`);
Expand Down