no-empty-static-block.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @fileoverview Rule to disallow empty static blocks.
  3. * @author Sosuke Suzuki
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Rule Definition
  8. //------------------------------------------------------------------------------
  9. /** @type {import('../shared/types').Rule} */
  10. module.exports = {
  11. meta: {
  12. type: "suggestion",
  13. docs: {
  14. description: "Disallow empty static blocks",
  15. recommended: false,
  16. url: "https://eslint.org/docs/rules/no-empty-static-block"
  17. },
  18. schema: [],
  19. messages: {
  20. unexpected: "Unexpected empty static block."
  21. }
  22. },
  23. create(context) {
  24. const sourceCode = context.getSourceCode();
  25. return {
  26. StaticBlock(node) {
  27. if (node.body.length === 0) {
  28. const closingBrace = sourceCode.getLastToken(node);
  29. if (sourceCode.getCommentsBefore(closingBrace).length === 0) {
  30. context.report({
  31. node,
  32. messageId: "unexpected"
  33. });
  34. }
  35. }
  36. }
  37. };
  38. }
  39. };