From 0bcfafb6fb4035276f1423108a824af660b297f6 Mon Sep 17 00:00:00 2001 From: dbale-altoros Date: Tue, 11 Jul 2023 12:34:40 -0300 Subject: [PATCH] add: list-rules command --- README.md | 1 + solhint.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/README.md b/README.md index 507c31e8..6d8e70e3 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ Options: Commands: stdin [options] linting of source code data provided to STDIN + list-rules display covered rules of current .solhint.json ``` ### Note The `--fix` option currently works only on "avoid-throw" and "avoid-sha3" rules diff --git a/solhint.js b/solhint.js index 225aa94c..ff5a1da2 100644 --- a/solhint.js +++ b/solhint.js @@ -40,6 +40,11 @@ function init() { .description('create configuration file for solhint') .action(writeSampleConfigFile) + program + .command('list-rules', null, { noHelp: false }) + .description('display covered rules of current .solhint.json') + .action(listRules) + if (process.argv.length <= 2) { program.help() } @@ -63,6 +68,7 @@ function execMainAction() { const reportLists = program.args.filter(_.isString).map(processPath) const reports = _.flatten(reportLists) + const warningsCount = reports.reduce((acc, i) => acc + i.warningCount, 0) const warningsNumberExceeded = program.opts().maxWarnings >= 0 && warningsCount > program.opts().maxWarnings @@ -207,6 +213,36 @@ function getFormatter(formatter) { } } +function listRules() { + const configPath = '.solhint.json' + if (!fs.existsSync(configPath)) { + console.log('Error!! Configuration does not exists') + process.exit(0) + } else { + const config = readConfig() + console.log('\nConfiguration File: \n', config) + + const currentPath = './.solhint.json' + const reportLists = linter.processPath(currentPath, readConfig()) + const rulesObject = reportLists[0].config + + console.log('\nRules: \n') + const orderedRules = Object.keys(rulesObject) + .sort() + .reduce((obj, key) => { + obj[key] = rulesObject[key] + return obj + }, {}) + + // eslint-disable-next-line func-names + Object.keys(orderedRules).forEach(function (key) { + console.log('- ', key, ': ', orderedRules[key]) + }) + } + + process.exit(0) +} + function exitWithCode(reports) { const errorsCount = reports.reduce((acc, i) => acc + i.errorCount, 0)