Definition for the custom rule was not found

Viewed 121

I am not really strong with setting up my custom npm packages, therefore I am asking for help. I am trying to test my custom ESLint plugin rules on another project. For this, I have set up two projects in one root directory and linked them, using the file linking option (find the image of the file structure attached):

"eslint-plugin-winniepukki-guidelines": "file:../guide"

.eslintrc configuration file on the project, where I want to use my custom ESLint plugin:

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    'airbnb-base',
  ],
  parserOptions: {
    ecmaVersion: 12,
    sourceType: 'module',
  },
  plugins: [
    'winniepukki-guidelines',
  ],
  rules: {
    'winniepukki-guidelines/use-license': 'error',
    'winniepukki-guidelines/avoid-names': 'error',
  },
};

Unfortunately, the rules do not apply properly with the following error: Definition for rule 'winniepukki-guidelines/avoid-names' was not found.eslint(winniepukki-guidelines/avoid-names). This is how the avoid-names.js file looks like:

module.exports = {
    meta: {
        messages: {
            avoidName: "Avoid using variables named '{{ name }}'"
        }
    },
    create(context) {
        return {
            Identifier(node) {
                if (node.name === "foo") {
                    context.report({
                        node,
                        messageId: "avoidName",
                        data: {
                            name: "foo",
                        }
                    });
                }
            }
        };
    }
};

And this is the ESLint package's index.js file itself, illustrating how do I export them:

const path = require('path');
const requireIndex = require('requireindex');

module.exports.rules = requireIndex(path.join(__dirname, 'rules'));

Project overview: https://i.stack.imgur.com/hLKcH.png

0 Answers
Related