Skip to content

Commit

Permalink
Add rules option to package.json
Browse files Browse the repository at this point in the history
So users can specify custom rules.

Works in `package.json`:

```json
{
  "standard": {
    "rules": {
      "semi": [2, "always"]
    }
  }
}
```

For user that need to tweak one rule for their particular project.

Fixes standard/standard#367
  • Loading branch information
feross committed Feb 4, 2016
1 parent f10e85a commit bc26ef8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
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 bc26ef8

Please sign in to comment.