Skip to content

Commit

Permalink
feat(bin): 0 exit code when no unused rules found
Browse files Browse the repository at this point in the history
Before, no unused rules always returned a non-zero exit code even when
no unused rules were found. Now, -u only returns a non-zero exit code
when an unused rule is found.

This makes eslint-find-rules an even better tool by being able to
be ran on CI when ESLint updates for configs.
  • Loading branch information
dustinspecker committed Apr 15, 2016
1 parent 1a64db4 commit 18068a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ var getRuleFinder = require('./rule-finder')
var specifiedFile = argv._[0]

var ruleFinder = getRuleFinder(specifiedFile)
var noUnusedRulesFound = false
Object.keys(options).forEach(function findRules(option) {
var rules
var ruleFinderMethod = ruleFinder[option]
if (argv[option] && ruleFinderMethod) {
rules = ruleFinderMethod()
/* istanbul ignore next */
if (rules.length) {
if (option === 'getUnusedRules') {
noUnusedRulesFound = true
}
console.log('\n' + options[option][0], 'rules\n') // eslint-disable-line no-console
console.log(rules.join(', ')) // eslint-disable-line no-console
}
}
})

if (processExitCode) {
if (processExitCode && noUnusedRulesFound) {
process.exit(processExitCode)
}
10 changes: 10 additions & 0 deletions test/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ describe('bin', function() {
assert.ok(getUnusedRules.called)
})

it('options -u|--unused and no unused rules found', function() {
getUnusedRules.returns([])
process.exit = function(status) {
assert.equal(status, 0)
}
process.argv[2] = '-u'
proxyquire('../src/bin', stub)
assert.ok(getUnusedRules.called)
})

it('option -u|--unused along with -n|no-error', function() {
process.exit = function(status) {
assert.equal(status, 0)
Expand Down

0 comments on commit 18068a3

Please sign in to comment.