I’m encountering an issue with integrating async/await operations within a custom ESLint rule. Here’s a simplified version of my code:
module.exports = {
meta: {
type: "problem",
docs: {
description: "This rule checks if any vulnerabilities appear in an imported package"
},
fixable: false,
schema: []
},
create(context) {
return {
async ImportDeclaration(node) {
const data = await apiCall();
context.report({
node,
message: "message"
});
}
};
}
}
The problem arises when I include an async operation (await apiCall()) within the ImportDeclaration callback. The context.report() method doesn’t seem to work as expected. However, when I remove the async/await operation, context.report() functions properly.
Can someone guide me on how to properly handle async operations within ESLint rule callbacks, ensuring that context.report() functions correctly? Any insights or alternative approaches would be greatly appreciated. Thank you!