简体   繁体   English

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

[英]eslint why does my plugin show Definition for rule was not found?

my plugin我的插件

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

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

runtime user config运行时用户配置

{
  "extends": [
    "bluelovers"
  ]
}

i can type in user repo我可以输入用户仓库

eslint --print-config .

this can show config and didn't error, i also see my plugin config inside the list这可以显示配置并且没有错误,我还在列表中看到了我的插件配置

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

but when i type eslint index.ts , it show error但是当我输入eslint index.ts ,它显示错误

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

index.ts索引.ts

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

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

how can i fix this??我怎样才能解决这个问题??

It means eslint cannot find rules in your index.js .这意味着 eslint 无法在您的index.js找到规则。 Try having a look at your index.js -exports.试着看看你的index.js -exports。 They should look something like this:它们应该如下所示:

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

And not like this:而不是这样:

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

If you're using TypeScript, change your export in index.ts from export default {...} to export = {...} .如果您使用的是 TypeScript,请将index.tsexport default {...}export default {...}更改为export = {...}

I think the key missing piece is no "plugins" session in config.我认为缺少的关键部分是配置中没有“插件”会话。


Why are you extending from "bluelovers"?你为什么要从“bluelovers”延伸出来? Do you have a shared config published?你有发布的共享配置吗? It seems like you're working on a plugin, not a config.看起来您正在开发插件,而不是配置。

You're then using a rule "@bluelovers/no-irregular-whitespace", with a leading @.然后,您将使用带有前导@ 的规则“@bluelovers/no-irregular-whitespace”。

If your plugin is published as "@bluelovers/eslint-plugin", you should try something like this:如果您的插件发布为“@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"]
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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