csf-component.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. /**
  3. * @fileoverview Component property should be set
  4. * @author Yann Braga
  5. */
  6. const utils_1 = require("../utils");
  7. const constants_1 = require("../utils/constants");
  8. const create_storybook_rule_1 = require("../utils/create-storybook-rule");
  9. const ast_1 = require("../utils/ast");
  10. module.exports = (0, create_storybook_rule_1.createStorybookRule)({
  11. name: 'csf-component',
  12. defaultOptions: [],
  13. meta: {
  14. type: 'suggestion',
  15. docs: {
  16. description: 'The component property should be set',
  17. categories: [constants_1.CategoryId.CSF],
  18. recommended: 'warn',
  19. },
  20. messages: {
  21. missingComponentProperty: 'Missing component property.',
  22. },
  23. schema: [],
  24. },
  25. create(context) {
  26. // variables should be defined here
  27. //----------------------------------------------------------------------
  28. // Helpers
  29. //----------------------------------------------------------------------
  30. // any helper functions should go here or else delete this section
  31. //----------------------------------------------------------------------
  32. // Public
  33. //----------------------------------------------------------------------
  34. return {
  35. ExportDefaultDeclaration(node) {
  36. const meta = (0, utils_1.getMetaObjectExpression)(node, context);
  37. if (!meta) {
  38. return null;
  39. }
  40. const componentProperty = meta.properties.find((property) => !(0, ast_1.isSpreadElement)(property) &&
  41. 'name' in property.key &&
  42. property.key.name === 'component');
  43. if (!componentProperty) {
  44. context.report({
  45. node,
  46. messageId: 'missingComponentProperty',
  47. });
  48. }
  49. },
  50. };
  51. },
  52. });