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

20,247

Solution 1

I think the key missing piece is no "plugins" section in config.


Why are you extending from "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 @.

If your plugin is published as "@bluelovers/eslint-plugin", you should try something like this:

{
    "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"]
    }
}

Solution 2

It means eslint cannot find rules in your index.js. Try having a look at your 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 = {...}.

Share:
20,247
bluelovers
Author by

bluelovers

Updated on December 23, 2021

Comments

  • bluelovers
    bluelovers over 2 years

    my 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

    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

       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;
    

    how can i fix this??

  • bluelovers
    bluelovers almost 5 years
    i have both, plugin and config, and plugin field is set on config
  • bluelovers
    bluelovers almost 5 years
    eslint-config-bluelovers , @bluelovers/eslint-plugin
  • O. R. Mapper
    O. R. Mapper almost 3 years
    Is this answer already outdated? The documentation provides an example for a rule, but the keyword rules appears nowhere in that article.
  • brooklynDadCore
    brooklynDadCore almost 3 years
    That link does not mention rules which is confusing, this one specifically about working with plugins talks about rules
  • Suncat2000
    Suncat2000 about 2 years
    What if your project doesn't have an index.js?