Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): accepts options corresponding to rules #2

Merged
merged 1 commit into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
})