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 new feature --ignore-path option #58

Merged
merged 11 commits into from
Sep 6, 2018
26 changes: 23 additions & 3 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ function init() {
program
.usage('[options] <file> [...other_files]')
.option('-f, --formatter [name]', 'report formatter name (stylish, table, tap, unix)')
.option('-w, --max-warnings [maxWarningsNumber]', 'number of warnings to trigger nonzero exit code')
.option('-q, --quiet', 'report errors only - default: false')
.option('--ignore-path [file_name]', 'file to use as your .solhintignore')
.description('Linter for Solidity programming language')
.action(execMainAction);

Expand All @@ -39,13 +41,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 Expand Up @@ -81,13 +92,22 @@ function writeSampleConfigFile() {
}

const readIgnore = _.memoize(function () {
let ignoreFile = '.solhintignore';
try {
if(program.ignorePath) {
ignoreFile = program.ignorePath;
}

return fs
.readFileSync('.solhintignore')
.readFileSync(ignoreFile)
.toString()
.split('\n')
.map(i => i.trim());
} catch (e) {

} catch (e){
if (program.ignorePath && e.code == 'ENOENT') {
console.error(`\nERROR: ${ignoreFile} is not a valid path.`);
}
return [];
}
});
Expand Down