no-empty-pattern.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @fileoverview Rule to disallow an empty pattern
  3. * @author Alberto Rodríguez
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. /** @type {import('../shared/types').Rule} */
  10. module.exports = {
  11. meta: {
  12. type: "problem",
  13. docs: {
  14. description: "Disallow empty destructuring patterns",
  15. recommended: true,
  16. url: "https://eslint.org/docs/rules/no-empty-pattern"
  17. },
  18. schema: [],
  19. messages: {
  20. unexpected: "Unexpected empty {{type}} pattern."
  21. }
  22. },
  23. create(context) {
  24. return {
  25. ObjectPattern(node) {
  26. if (node.properties.length === 0) {
  27. context.report({ node, messageId: "unexpected", data: { type: "object" } });
  28. }
  29. },
  30. ArrayPattern(node) {
  31. if (node.elements.length === 0) {
  32. context.report({ node, messageId: "unexpected", data: { type: "array" } });
  33. }
  34. }
  35. };
  36. }
  37. };