securityos/node_modules/eslint-plugin-unicorn/rules/prefer-event-target.js

40 lines
744 B
JavaScript
Raw Permalink Normal View History

2024-09-06 15:32:35 +00:00
'use strict';
const {matches} = require('./selectors/index.js');
const MESSAGE_ID = 'prefer-event-target';
const messages = {
[MESSAGE_ID]: 'Prefer `EventTarget` over `EventEmitter`.',
};
const selector = [
'Identifier',
'[name="EventEmitter"]',
matches([
'ClassDeclaration > .superClass',
'ClassExpression > .superClass',
'NewExpression > .callee',
]),
].join('');
/** @param {import('eslint').Rule.RuleContext} context */
const create = () => ({
[selector](node) {
return {
node,
messageId: MESSAGE_ID,
};
},
});
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
create,
meta: {
type: 'suggestion',
docs: {
description: 'Prefer `EventTarget` over `EventEmitter`.',
},
messages,
},
};