prefer-event-target.js 744 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. const {matches} = require('./selectors/index.js');
  3. const MESSAGE_ID = 'prefer-event-target';
  4. const messages = {
  5. [MESSAGE_ID]: 'Prefer `EventTarget` over `EventEmitter`.',
  6. };
  7. const selector = [
  8. 'Identifier',
  9. '[name="EventEmitter"]',
  10. matches([
  11. 'ClassDeclaration > .superClass',
  12. 'ClassExpression > .superClass',
  13. 'NewExpression > .callee',
  14. ]),
  15. ].join('');
  16. /** @param {import('eslint').Rule.RuleContext} context */
  17. const create = () => ({
  18. [selector](node) {
  19. return {
  20. node,
  21. messageId: MESSAGE_ID,
  22. };
  23. },
  24. });
  25. /** @type {import('eslint').Rule.RuleModule} */
  26. module.exports = {
  27. create,
  28. meta: {
  29. type: 'suggestion',
  30. docs: {
  31. description: 'Prefer `EventTarget` over `EventEmitter`.',
  32. },
  33. messages,
  34. },
  35. };