I have written a custom ESLint rule as follows:
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Test Description",
category: "Common",
recommended: true,
url: ""
},
fixable: "code",
schema: [] // no options
},
create: function (context) {
return {
ClassDeclaration(node) {
var data = ""// I want to pass value here from CMD
if (node.id.name === data)
{
context.report({
node: node,
message: "ESLint rule triggered"
});
}
}
}
}
}
And I am running ESLint for a Test.js file using following command in CMD.
npx eslint Test.js
Is there a way in which I can pass data to the rule from CMD while executing eslint command? I want to pass a value to the variable 'data' from
Yes, it's possible with Node.js environment variables.
process.env
includes environment variables you set manually:You might also consider using rule options set in the ESLint config. Those can be set with environment variables, too.