eslint为什么我的插件未显示“规则定义”?

时间:2019-06-01 05:31:46

标签: javascript node.js typescript eslint

我的插件

@ bluelovers / eslint-plugin https://github.com/bluelovers/ws-node-bluelovers/tree/master/packages/eslint-plugin

我的基本配置 https://github.com/bluelovers/ws-node-bluelovers/blob/master/packages/eslintrc/.eslintrc.json

运行时用户配置

{
  "extends": [
    "bluelovers"
  ]
}

我可以输入用户回购

eslint --print-config .

这可以显示配置并且没有错误,我也可以在列表中看到我的插件配置

   "@bluelovers/no-irregular-whitespace": [
      "error",
      {
        "skipComments": true,
        "skipStrings": false,
        "skipTemplates": false,
        "skipRegExps": false,
        "ignores": [
          " "
        ]
      }
    ],

但是当我键入eslint index.ts时,它会显示错误

   1:1   error    Definition for rule '@bluelovers/no-irregular-whitespace' was not found  @bluelovers/no-irregular-whitespace

index.ts

export const r = /[ \t\uFEFF\xA0 ]+$/;

const IRREGULAR_WHITESPACE = /[\f\v  ᠎           ​   ]+/mgu;

我该如何解决?

2 个答案:

答案 0 :(得分:2)

这意味着eslint无法在您的index.js中找到规则。尝试看看您的index.js导出。他们应该看起来像这样:

module.exports = {
  rules: {
    [myRuleName]: myRule
  }
};

不是这样的:

exports.default = {
  rules: {
    [myRuleName]: myRule
  }
};

如果您使用的是TypeScript,请将index.ts中的导出从export default {...}更改为exports = {...}

答案 1 :(得分:0)

我认为缺少的关键是配置中没有“插件”会话。


您为什么要从“ bluelovers”扩展?您是否发布了共享配置?似乎您正在使用插件,而不是配置。

然后,您使用规则“ @ bluelovers / no-irregular-whitespace”,并在前导@。

如果您的插件发布为“ @ bluelovers / eslint-plugin”,则应尝试以下操作:

{
    "plugins": ["@bluelovers"],
    "extends": ["@bluelovers"], // Assuming you have @bluelovers/eslint-config published, otherwise this might look different or could be skipped
    "rules": {
        "@bluelovers/no-irregular-whitespace": ["error"]
    }
}
相关问题