Reputation: 13
I want to create couple of custom rule for my nodejs project by eslint and generate
one json analysis report but while running my custom rules it's throwing an error say
1:1 error Definition for rule 'D:/Sports/eslint-rules/no-log.js' was not found
I have created one custom rule with ESlint for my nodejs project
here is my .eslintrc.js file
module.exports = {
env: {
node: true,
},
plugins: ['eslint-rules'],
rules: {
'eslint-rules/no-log': 'error',
'eslint-rules/max-params': ['error', { maxParams: 3 }],
},
};
and here is my one of the custom rule file named as eslint-rules/no-log.js
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow console.log() in code",
category: "Best Practices",
recommended: true,
},
schema: [],
},
create: function (context) {
return {
CallExpression(node) {
const { callee } = node;
if (
callee.type === "MemberExpression" &&
callee.object &&
callee.object.name === "console" &&
callee.property &&
callee.property.name === "log"
) {
context.report({
node,
message: "Avoid using console.log() in code.",
});
}
},
};
},
};
and i run my custom rule through this command npx eslint ./ --format json --output-file eslint-report.json
Upvotes: 0
Views: 674
Reputation: 1512
I came from Google because I have the very same error message. Didn't want to use additional plugins. Nor --rulesdir
, because it's deprecated in favor of Plugins – but the official How-To on Plugins lacks some important information for Node.js-user like me and OP: The Plugin has to be "installed", which might be done locally, via package.json
:
{
// ...
"devDependencies": {
// ...
"eslint-plugin-acme": "file:./path/to/plugin"
}
}
Find details on the actual plugin here (based on here), but the answer to "why is the ESLint plugin not found when linting is run via Node" is "because it's yet unknown to Node".
Upvotes: 0
Reputation: 5188
Local rules in eslint need one of the following:
--rulesdir
option pointing at the location of your rules (this won't work if you have an IDE plugin for eslint though)Upvotes: 0