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 --max-warnings [int] option #57

Merged
14 changes: 12 additions & 2 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function init() {
program
.usage('[options] <file> [...other_files]')
.option('-f, --formatter [name]', 'report formatter name (stylish, table, tap, unix)')
.option('-q, --quiet', 'report errors only - default: false')
.option('-w, --max-warnings [maxWarningsNumber]', 'number of warnings to trigger nonzero exit code')
.option('-q, --quiet', 'report errors only')
.description('Linter for Solidity programming language')
.action(execMainAction);

Expand All @@ -39,13 +40,22 @@ function init() {
function execMainAction() {
const reportLists = program.args.filter(_.isString).map(processPath);
const reports =_.flatten(reportLists);
const warningsNumberExceeded = program.maxWarnings >= 0 && reports[0].warningCount >= program.maxWarnings;

if (program.quiet) {
// filter the list of reports, to set errors only.
reports[0].reports = reports[0].reports.filter(i => i.severity === 2);
}

printReports(reports, program.formatter);
if (printReports(reports, program.formatter)) {
if (program.maxWarnings && !reports[0].errorCount && warningsNumberExceeded) {
console.log(
'Solhint found more warnings than the maximum specified (maximum: %s)',
program.maxWarnings);
process.exit(1);
}
}

exitWithCode(reports);
}

Expand Down