默认情况下加载eslint插件规则

时间:2016-09-01 07:54:28

标签: javascript eslint

我创建了一个eslint插件(即eslint-plugin-components),它有两个规则:no-waitno-huge-timeout。如果我像这样将这两个规则添加到.eslintrc,则eslint可以正常工作:

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

我一直想做的是将它们加载到我的插件索引中,如下所示:

'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
  }
};

但这种方式eslint不会加载它们。我的问题是,如果可以做我正在尝试做的事情,我怎么能这样做。

1 个答案:

答案 0 :(得分:1)

根据documentation,您必须在configs中添加命名配置:

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

你会在.eslintrc

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