Skip to content

Commit

Permalink
Merge pull request #57 from Flet/configure
Browse files Browse the repository at this point in the history
Add rules option to package.json
  • Loading branch information
feross committed Feb 4, 2016
2 parents befe48a + bc26ef8 commit c64f749
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function Linter (opts) {
self.eslintConfig = defaults(opts.eslintConfig, {
useEslintrc: false,
globals: [],
plugins: []
plugins: [],
rules: {}
})
if (!self.eslintConfig) {
throw new Error('No eslintConfig passed.')
Expand All @@ -47,6 +48,7 @@ function Linter (opts) {
* @param {Object=} opts options object
* @param {Array.<string>=} opts.globals custom global variables to declare
* @param {Array.<string>=} opts.plugins custom eslint plugins
* @param {Object=} opts.rules custom eslint rules
* @param {string=} opts.parser custom js parser (e.g. babel-eslint)
* @param {function(Error, Object)} cb callback
*/
Expand All @@ -73,6 +75,7 @@ Linter.prototype.lintText = function (text, opts, cb) {
* @param {string=} opts.cwd current working directory (default: process.cwd())
* @param {Array.<string>=} opts.globals custom global variables to declare
* @param {Array.<string>=} opts.plugins custom eslint plugins
* @param {Object=} opts.rules custom eslint rules
* @param {string=} opts.parser custom js parser (e.g. babel-eslint)
* @param {function(Error, Object)} cb callback
*/
Expand Down Expand Up @@ -121,6 +124,7 @@ Linter.prototype.parseOpts = function (opts) {

setGlobals(opts.globals || opts.global)
setPlugins(opts.plugins || opts.plugin)
setRules(opts.rules || opts.rule)
setParser(opts.parser)

var root
Expand All @@ -131,6 +135,7 @@ Linter.prototype.parseOpts = function (opts) {
if (packageOpts) {
setGlobals(packageOpts.globals || packageOpts.global)
setPlugins(packageOpts.plugins || packageOpts.plugin)
setRules(packageOpts.rules || packageOpts.rule)
if (!opts.parser) setParser(packageOpts.parser)
}
}
Expand All @@ -145,6 +150,11 @@ Linter.prototype.parseOpts = function (opts) {
opts.eslintConfig.plugins = self.eslintConfig.plugins.concat(plugins)
}

function setRules (rules) {
if (!rules) return
opts.eslintConfig.rules = extend(opts.eslintConfig.rules, rules)
}

function setParser (parser) {
if (!parser) return
opts.eslintConfig.parser = parser
Expand Down

0 comments on commit c64f749

Please sign in to comment.