Skip to content

Commit

Permalink
Merge pull request #2 from sarbbottam/eslint-rule-finder
Browse files Browse the repository at this point in the history
feat(cli): accepts options corresponding to rules
  • Loading branch information
sarbbottam committed Apr 7, 2016
2 parents d342b9f + e2cf04e commit 5d3a11f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eslint-find-new-rules",
"name": "eslint-rule-finder",
"version": "0.0.0-semantically-released",
"description": "Find built-in ESLint rules you don't have in your custom config.",
"main": "src/rule-finder.js",
Expand All @@ -16,7 +16,7 @@
"report-coverage": "cat ./coverage/lcov.info | node_modules/.bin/codecov"
},
"bin": {
"eslint-find-new-rules": "src/bin.js"
"eslint-rule-finder": "src/bin.js"
},
"keywords": [],
"author": "Michał Gołębiowski <m.goleb@gmail.com>",
Expand All @@ -42,7 +42,8 @@
"opt-cli": "^1.1.1",
"proxyquire": "1.7.4",
"semantic-release": "4.3.5",
"validate-commit-msg": "2.4.0"
"validate-commit-msg": "2.4.0",
"yargs": "^4.4.0"
},
"peerDependencies": {
"eslint": "^2.0.0"
Expand Down Expand Up @@ -72,10 +73,10 @@
},
"repository": {
"type": "git",
"url": "https://github.com/kentcdodds/eslint-find-new-rules.git"
"url": "https://github.com/sarbbottam/eslint-rule-finder.git"
},
"bugs": {
"url": "https://github.com/kentcdodds/eslint-find-new-rules/issues"
"url": "https://github.com/sarbbottam/eslint-rule-finder/issues"
},
"homepage": "https://github.com/kentcdodds/eslint-find-new-rules#readme"
}
"homepage": "https://github.com/sarbbottam/eslint-rule-finder#readme"
}
34 changes: 24 additions & 10 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

'use strict'

// Prints rules recognized by ESLint that don't appear in the given config
// preset. It helps with upgrading the preset when new ESLint gets released.
var getRuleFinder = require('./rule-finder')
var specifiedFile = process.argv[2]
var ruleFinder = getRuleFinder(specifiedFile)
var options = {
getCurrentRules: ['current', 'c'],
getPluginRules: ['plugin', 'p'],
getAllAvailableRules: ['all-available', 'a'],
getUnusedRules: ['unused', 'u'],
}

var newRules = ruleFinder.getUnusedRules()
var argv = require('yargs')
.boolean(Object.keys(options))
.alias(options)
.argv

if (newRules.length) {
console.log('New rules to add to the config: ' + newRules.join(', ') + '.') // eslint-disable-line no-console
process.exit(1)
}
var getRuleFinder = require('./rule-finder')
var specifiedFile = argv._[0]

var ruleFinder = getRuleFinder(specifiedFile)
Object.keys(options).forEach(function findRules(option) {
var rules
if (argv[option]) {
rules = ruleFinder[option]()
if (rules.length) {
console.log('\n' + options[option][0], 'rules\n') // eslint-disable-line no-console
console.log(rules.join(', ')) // eslint-disable-line no-console
}
}
})

0 comments on commit 5d3a11f

Please sign in to comment.