{"version":3,"file":"linesBeforeBlock.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/linesBeforeBlock.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\n/**\n * Punctuators that begin a logical group should not require a line before it skipped. Specifically\n * `[` starts an array, `{` starts an object or block, `(` starts a grouping, and `=` starts a\n * declaration (like a variable or a type alias).\n */\nconst startPunctuators = new Set([\n  '(', '=', '[', '{',\n]);\n\nexport default iterateJsdoc(({\n  context,\n  jsdocNode,\n  report,\n  sourceCode,\n  utils,\n}) => {\n  const {\n    checkBlockStarts,\n    excludedTags = [\n      'type',\n    ],\n    ignoreSameLine = true,\n    ignoreSingleLines = true,\n    lines = 1,\n  } = context.options[0] || {};\n\n  if (utils.hasATag(excludedTags)) {\n    return;\n  }\n\n  const tokensBefore = sourceCode.getTokensBefore(jsdocNode, {\n    includeComments: true,\n  });\n  const tokenBefore = tokensBefore.at(-1);\n  if (\n    !tokenBefore || (\n      tokenBefore.type === 'Punctuator' &&\n      !checkBlockStarts &&\n      startPunctuators.has(tokenBefore.value)\n    )\n  ) {\n    return;\n  }\n\n  if (tokenBefore.loc?.end?.line + lines >=\n  /** @type {number} */\n      (jsdocNode.loc?.start?.line)\n  ) {\n    const startLine = jsdocNode.loc?.start?.line;\n    const sameLine = tokenBefore.loc?.end?.line === startLine;\n\n    if (sameLine && ignoreSameLine) {\n      return;\n    }\n\n    if (ignoreSingleLines && jsdocNode.loc?.start.line === jsdocNode.loc?.end.line) {\n      return;\n    }\n\n    /** @type {import('eslint').Rule.ReportFixer} */\n    const fix = (fixer) => {\n      let indent = '';\n      if (sameLine) {\n        const spaceDiff = /** @type {number} */ (jsdocNode.loc?.start?.column) -\n        /** @type {number} */ (tokenBefore.loc?.end?.column);\n        // @ts-expect-error Should be a comment\n        indent = /** @type {import('estree').Comment} */ (\n          jsdocNode\n        ).value.match(/^\\*\\n([\\t ]*) \\*/v)?.[1]?.slice(spaceDiff);\n        if (!indent) {\n          /** @type {import('eslint').AST.Token|import('estree').Comment|undefined} */\n          let tokenPrior = tokenBefore;\n          let startColumn;\n          while (tokenPrior && tokenPrior?.loc?.start?.line === startLine) {\n            startColumn = tokenPrior.loc?.start?.column;\n            tokenPrior = tokensBefore.pop();\n          }\n\n          indent = ' '.repeat(\n            /* c8 ignore next */\n            /** @type {number} */ (startColumn ? startColumn - 1 : 0),\n          );\n        }\n      }\n\n      return fixer.insertTextAfter(\n        /** @type {import('eslint').AST.Token} */\n        (tokenBefore),\n        '\\n'.repeat(lines) +\n        (sameLine ? '\\n' + indent : ''),\n      );\n    };\n\n    report(`Required ${lines} line(s) before JSDoc block`, fix);\n  }\n}, {\n  iterateAllJsdocs: true,\n  meta: {\n    docs: {\n      description: 'Enforces minimum number of newlines before JSDoc comment blocks',\n      url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/lines-before-block.md#repos-sticky-header',\n    },\n    fixable: 'code',\n    schema: [\n      {\n        additionalProperties: false,\n        properties: {\n          checkBlockStarts: {\n            description: `Whether to additionally check the start of blocks, such as classes or functions.\nDefaults to \\`false\\`.`,\n            type: 'boolean',\n          },\n          excludedTags: {\n            description: `An array of tags whose presence in the JSDoc block will prevent the\napplication of the rule. Defaults to \\`['type']\\` (i.e., if \\`@type\\` is present,\nlines before the block will not be added).`,\n            items: {\n              type: 'string',\n            },\n            type: 'array',\n          },\n          ignoreSameLine: {\n            description: `This option excludes cases where the JSDoc block occurs on the same line as a\npreceding code or comment. Defaults to \\`true\\`.`,\n            type: 'boolean',\n          },\n          ignoreSingleLines: {\n            description: `This option excludes cases where the JSDoc block is only one line long.\nDefaults to \\`true\\`.`,\n            type: 'boolean',\n          },\n          lines: {\n            description: 'The minimum number of lines to require. Defaults to 1.',\n            type: 'integer',\n          },\n        },\n        type: 'object',\n      },\n    ],\n    type: 'suggestion',\n  },\n});\n"],"mappings":";;;;;;AAAA;AAA8C;AAE9C;AACA;AACA;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,IAAI,GAAG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