Skip to content

Commit

Permalink
feat(lib): Support extends and plugins
Browse files Browse the repository at this point in the history
Collect configured rules using the eslint api methods, taking extending configs and plugins into
account.
  • Loading branch information
ta2edchimp committed Mar 19, 2016
1 parent fd8de57 commit 18b8aae
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@
// 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 path = require('path')
var eslint = require('eslint')
var isAbsolute = require('path-is-absolute')
var findNewRules = require('./index')

var currentRules = Object.keys(getConfig().rules)
var currentRules = getRules()
var newRules = findNewRules(currentRules)

if (newRules.length) {
console.log('New rules to add to the config: ' + newRules.join(', ') + '.') // eslint-disable-line no-console
process.exit(1)
}

function getConfig() {
function getConfigFile() {
var specifiedFile = process.argv[2]
if (specifiedFile) {
// this is being called like: eslint-find-new-rules eslint-config-mgol
if (isAbsolute(specifiedFile)) {
return require(specifiedFile)
return specifiedFile
} else {
return require(path.join(process.cwd(), specifiedFile))
return path.join(process.cwd(), specifiedFile)
}
} else {
// this is not being called with an arg. Use the package.json `main`
return require(process.cwd())
return path.join(process.cwd(), 'package.json')
}
}

function getConfig(configFile) {
var cliEngine = new eslint.CLIEngine({
// ignore any config applicable depending on the location on the filesystem
useEslintrc: false,
// point to the particular config
configFile,
})
var config = cliEngine.getConfigForFile(configFile)
return config
}

function getRules() {
var configFile = getConfigFile()
var config = getConfig(configFile)
var rules = Object.keys(config.rules)
return rules
}

0 comments on commit 18b8aae

Please sign in to comment.