From 3ec6762b47a5d2a8f0f2eba2932e6642a613c5d8 Mon Sep 17 00:00:00 2001 From: florblue Date: Fri, 24 Aug 2018 17:23:17 -0300 Subject: [PATCH 1/3] Add --quiet option. To do this, it was added an auxiliar function that filter only error from linter results, and it was modified execMainAction() function to add the quiet option --- solhint.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/solhint.js b/solhint.js index b2f8daf8..b57d590f 100755 --- a/solhint.js +++ b/solhint.js @@ -17,6 +17,11 @@ function init() { .description('Linter for Solidity programming language') .action(execMainAction); + program + .usage('[options] [...other_files]') + .option('-q, --quiet', 'report errors only - default: false') + .action(execMainAction); + program .command('stdin') .description('linting of source code data provided to STDIN') @@ -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::::'); + // Setting int the report list errors only. + reports[0].reports = getErrorResults(reports); + } + printReports(reports, program.formatter); exitWithCode(reports); } @@ -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); + return reporterErrors; +} + function printReports(reports, formatter) { const formatterName = formatter || 'stylish'; const formatterFn = require(`eslint/lib/formatters/${formatterName}`); From 88858a7e89e345faa240f348de95293dddf4e688 Mon Sep 17 00:00:00 2001 From: florblue Date: Wed, 29 Aug 2018 14:40:01 -0300 Subject: [PATCH 2/3] It was done the requested changes. Delete unnecesary lines. Delete log when quiet option in enable. --- solhint.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/solhint.js b/solhint.js index b57d590f..2803e869 100755 --- a/solhint.js +++ b/solhint.js @@ -18,9 +18,7 @@ function init() { .action(execMainAction); program - .usage('[options] [...other_files]') - .option('-q, --quiet', 'report errors only - default: false') - .action(execMainAction); + .option('-q, --quiet', 'report errors only - default: false'); program .command('stdin') @@ -45,7 +43,6 @@ function execMainAction() { const reports =_.flatten(reportLists); if (program.quiet) { - console.log('::::Quiet mode enabled - filtering out warnings::::'); // Setting int the report list errors only. reports[0].reports = getErrorResults(reports); } @@ -131,8 +128,8 @@ function processPath(path) { * @returns {LintResult[]} The filtered results. **/ function getErrorResults(reporter) { - const reporterErrors = reporter[0].reports.filter(i => i.severity === 2); - return reporterErrors; + return reporter[0].reports.filter(i => i.severity === 2); + } function printReports(reports, formatter) { From a2f5daa56c877cf19c0267ad9bdab7b9b6941876 Mon Sep 17 00:00:00 2001 From: florblue Date: Thu, 30 Aug 2018 11:35:01 -0300 Subject: [PATCH 3/3] Remove unnecesary function and move the filtering of errors into execMainAction(). Move new --quiet option declaration to the correct place. --- solhint.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/solhint.js b/solhint.js index 2803e869..44341d28 100755 --- a/solhint.js +++ b/solhint.js @@ -14,12 +14,10 @@ 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') .description('Linter for Solidity programming language') .action(execMainAction); - program - .option('-q, --quiet', 'report errors only - default: false'); - program .command('stdin') .description('linting of source code data provided to STDIN') @@ -43,8 +41,8 @@ function execMainAction() { const reports =_.flatten(reportLists); if (program.quiet) { - // Setting int the report list errors only. - reports[0].reports = getErrorResults(reports); + // filter the list of reports, to set errors only. + reports[0].reports = reports[0].reports.filter(i => i.severity === 2); } printReports(reports, program.formatter); @@ -121,17 +119,6 @@ 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) { - return reporter[0].reports.filter(i => i.severity === 2); - -} - function printReports(reports, formatter) { const formatterName = formatter || 'stylish'; const formatterFn = require(`eslint/lib/formatters/${formatterName}`);