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

Add rules option to package.json #57

Merged
merged 1 commit into from
Feb 4, 2016
Merged
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
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