From ed5416f525f66f5a48f084709eb2311d86c1a167 Mon Sep 17 00:00:00 2001 From: toruichikawa Date: Mon, 8 Aug 2022 13:14:51 +0200 Subject: [PATCH] fix: TypeError: Cannot read property 'errorCount' of undefined Without this patch, there are situations when the .solhintignore file causes all inputs files being ignored. This is a problem because the 'reports' variable ends up being an empty array, and therefore reports[0] is undefined. This patch solves the problem by checking that reports array exists and has a length greater than 0. Thanks to Adam Spiers (@aspiers) who originally discovered a bug. Issue-URL: https://bytemeta.vip/repo/protofire/solhint/issues/239 --- solhint.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/solhint.js b/solhint.js index eff8b64..aa8ca6e 100755 --- a/solhint.js +++ b/solhint.js @@ -94,7 +94,13 @@ function execMainAction() { } if (printReports(reports, formatterFn)) { - if (program.maxWarnings && !reports[0].errorCount && warningsNumberExceeded) { + if ( + program.maxWarnings && + reports && + reports.length > 0 && + !reports[0].errorCount && + warningsNumberExceeded + ) { console.log( 'Solhint found more warnings than the maximum specified (maximum: %s)', program.maxWarnings