简体   繁体   中英

Load eslint plugin rules by default

I have created a eslint plugin (ie eslint-plugin-components) with two rules: no-wait and no-huge-timeout . If I add these two rules to .eslintrc like this, eslint works properly:

{
  "extends": "airbnb-base",
  "plugins": ["components"],
  "rules": {
    "components/no-wait": 2,
    "components/no-huge-timeouts": 2
  }
}

What I've been trying to do is to load them at my plugin's index, like this:

'use strict';

var requireIndex = require('requireindex');

module.exports.rules = requireIndex(__dirname + '/lib/rules');

module.exports.configs = {
  rules: {
    'components/no-wait': 2,
    'components/no-huge-timeouts': 2
  }
};

But this way eslint does not load them. My question would be if it's posible to do what I'm trying to do and how could I do that.

According to the documentation , you have to include a named configuration in configs :

module.exports.configs = {
  some_name: {
    rules: {
      'components/no-wait': 2,
      'components/no-huge-timeouts': 2
    }
  }
};

And you would reference that named configuration in your .eslintrc :

{
  "plugins": ["components"],
  "extends": [
    "airbnb-base",
    "plugin:components/some_name"
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM