diff --git a/solhint.js b/solhint.js index 44341d28..8ac8762d 100755 --- a/solhint.js +++ b/solhint.js @@ -14,7 +14,8 @@ function init() { program .usage('[options] [...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); @@ -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); }