Skip to content

Commit

Permalink
add: list-rules command
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Jul 11, 2023
1 parent 827c88b commit 9d20960
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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
Expand Down Expand Up @@ -207,6 +213,35 @@ 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 reportLists = linter.processPath(configPath, 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)

Expand Down

0 comments on commit 9d20960

Please sign in to comment.