"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _lodash = _interopRequireDefault(require("lodash"));

var _iterateJsdoc = _interopRequireDefault(require("../iterateJsdoc"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _default = (0, _iterateJsdoc.default)(({
  jsdoc,
  report,
  utils,
  context
}) => {
  if (utils.avoidDocs()) {
    return;
  }

  const _ref = context.options[0] || {},
        _ref$descriptionStyle = _ref.descriptionStyle,
        descriptionStyle = _ref$descriptionStyle === void 0 ? 'body' : _ref$descriptionStyle;

  let targetTagName = utils.getPreferredTagName({
    // We skip reporting except when `@description` is essential to the rule,
    //  so user can block the tag and still meaningfully use this rule
    //  even if the tag is present (and `check-tag-names` is the one to
    //  normally report the fact that it is blocked but present)
    skipReportingBlockedTag: descriptionStyle !== 'tag',
    tagName: 'description'
  });

  if (!targetTagName) {
    return;
  }

  const isBlocked = typeof targetTagName === 'object' && targetTagName.blocked;

  if (isBlocked) {
    targetTagName = targetTagName.tagName;
  }

  const checkDescription = description => {
    const exampleContent = _lodash.default.compact(description.trim().split('\n'));

    return exampleContent.length;
  };

  if (descriptionStyle !== 'tag') {
    if (checkDescription(jsdoc.description || '')) {
      return;
    }

    if (descriptionStyle === 'body') {
      report('Missing JSDoc block description.');
      return;
    }
  }

  const functionExamples = isBlocked ? [] : _lodash.default.filter(jsdoc.tags, {
    tag: targetTagName
  });

  if (!functionExamples.length) {
    report(descriptionStyle === 'any' ? `Missing JSDoc block description or @${targetTagName} declaration.` : `Missing JSDoc @${targetTagName} declaration.`);
    return;
  }

  functionExamples.forEach(example => {
    if (!checkDescription(`${example.name} ${example.description}`)) {
      report(`Missing JSDoc @${targetTagName} description.`);
    }
  });
}, {
  contextDefaults: true,
  meta: {
    schema: [{
      additionalProperties: false,
      properties: {
        contexts: {
          items: {
            type: 'string'
          },
          type: 'array'
        },
        descriptionStyle: {
          enum: ['body', 'tag', 'any'],
          type: 'string'
        },
        exemptedBy: {
          items: {
            type: 'string'
          },
          type: 'array'
        }
      },
      type: 'object'
    }],
    type: 'suggestion'
  }
});

exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=requireDescription.js.map