【问题标题】:eslint why does my plugin show Definition for rule was not found?eslint 为什么我的插件显示未找到规则定义?
【发布时间】:2019-10-17 15:16:55
【问题描述】:

我的插件

@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;

我该如何解决这个问题??

【问题讨论】:

  • 至少在我的情况下这不是配置问题,只需重新启动 VS Code 即可解决。因此,在您开始深入研究十几个 eslint 插件的文档之前,您可能想尝试一下。我将把它留在这里作为提示。

标签: javascript node.js typescript eslint


【解决方案1】:

我认为关键的缺失部分是配置中没有“插件”部分。


你为什么要从“blueloves”延伸出来?您是否发布了共享配置?看起来你正在开发一个插件,而不是一个配置。

然后,您将使用规则“@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"]
    }
}

【讨论】:

  • 我两者都有,插件和配置,并且插件字段设置在配置上
  • eslint-config-bluelovers ,@bluelovers/eslint-plugin
【解决方案2】:

这意味着 eslint 在你的index.js 中找不到规则。尝试查看您的index.js-exports。它们应该看起来像这样:

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

不是这样的:

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

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

【讨论】:

  • 这个答案已经过时了吗? documentation 提供了一个规则示例,但关键字rules 在那篇文章中没有出现。
  • 那个链接没有提到rules这令人困惑,这个one专门关于使用插件谈论rules
猜你喜欢
  • 1970-01-01
  • 2021-05-08
  • 2021-10-22
  • 1970-01-01
  • 2019-05-04
  • 2017-04-11
  • 2017-06-19
  • 2021-05-03
  • 2019-02-09
相关资源
最近更新 更多