eslint-plugin-sonarjs
Version:
SonarJS rules for ESLint
39 lines (38 loc) • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.rule = void 0;
const index_js_1 = require("../helpers/index.js");
const meta_js_1 = require("./meta.js");
const NODES = new Set([
'ArrayExpression',
'ClassExpression',
'ObjectExpression',
'Literal',
'TemplateLiteral',
]);
exports.rule = {
meta: (0, index_js_1.generateMeta)(meta_js_1.meta, {
messages: {
asFunction: 'Literal should not be used as function.',
asTagFunction: 'Literal should not be used as tag function.',
},
}),
create(context) {
const processNode = (node, messageId) => {
if (NODES.has(node.type)) {
context.report({
node,
messageId,
});
}
};
return {
CallExpression(node) {
processNode(node.callee, 'asFunction');
},
TaggedTemplateExpression(node) {
processNode(node.tag, 'asTagFunction');
},
};
},
};
;