footer-leading-blank.js 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.footerLeadingBlank = void 0;
  7. const to_lines_1 = __importDefault(require("@commitlint/to-lines"));
  8. const message_1 = __importDefault(require("@commitlint/message"));
  9. const footerLeadingBlank = (parsed, when = 'always') => {
  10. // Flunk if no footer is found
  11. if (!parsed.footer) {
  12. return [true];
  13. }
  14. const negated = when === 'never';
  15. const rawLines = (0, to_lines_1.default)(parsed.raw);
  16. const bodyLines = parsed.body ? (0, to_lines_1.default)(parsed.body) : [];
  17. const bodyOffset = bodyLines.length > 0 ? rawLines.indexOf(bodyLines[0]) : 1;
  18. const [leading] = rawLines.slice(bodyLines.length + bodyOffset);
  19. // Check if the first line of footer is empty
  20. const succeeds = leading === '';
  21. return [
  22. negated ? !succeeds : succeeds,
  23. (0, message_1.default)([
  24. 'footer',
  25. negated ? 'may not' : 'must',
  26. 'have leading blank line',
  27. ]),
  28. ];
  29. };
  30. exports.footerLeadingBlank = footerLeadingBlank;
  31. //# sourceMappingURL=footer-leading-blank.js.map