Eslint v8.50, using eslintrc.js config format
I am following custom rule tutorial to create custom rule (which requires a plugin from what I understand), but I'm not able import my local plugin.
Tried following:
Plugins array cannot includes file paths erroreslint-plugin-example dir with index.js in root of the project (next to eslintrc.js) and provide "eslint-plugin-example" in plugins config: config not foundThe only way I managed to make it work is to do npm i ./eslint-plugin-example --save-dev which created symlink in node_modules. This feels too complicated for such simple thing as including local rule/plugin.
Is there any other way to achieve it? (without migrating to flat config)
I also didn't find another solution, but it works quite well.
The file structure:

eslint-plugin-custom/index.js:
module.exports = {
rules: {
'my-custom-rule': require('./rules/my-custom-rule')
}
};
eslint-plugin-custom/package.json (need to install as package):
{
"name": "eslint-plugin-custom",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
eslint-plugin-custom/rules/my-custom-rule.js (replace code with your rule):
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow the use of console.log',
category: 'Best Practices',
recommended: false
},
schema: [], // no options
},
create: function(context) {
return {
CallExpression(node) {
if (node.callee.object && node.callee.object.name === 'console' && node.callee.property.name === 'log') {
context.report({
node,
message: 'Unexpected console.log statement.'
});
}
}
};
}
};
updates in the eslintrc.json:
{
...
"plugins": [
...,
"custom"
],
"overrides": [
...
{
...
"rules": {
...
"custom/my-custom-rule": "error"
}
}
]
}
install command:
npm i .\eslint-plugin-custom --save-dev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With