eslint-plugin-jsdoc 63.1.0 → 63.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,7 @@ const prefixLinkAttemptRegex = /(?<!\\)\[[^\]\r\n]*\]\{@link[^\}\r\n]*(?:\}|$)/v
14
14
  const pipeLinkAttemptRegex = /\{@link[^\}\r\n]*\|[^\}\r\n]*(?:\}|$)/v;
15
15
  const scopedPackageNameRegex = /^@[\w.\-]+\/[\w.\-]+/v;
16
16
  const markdownCodeSpanRegex = /(?<!\\)(`+)(?!`)[\s\S]*?(?<!`)\1(?!`)/gv;
17
+ const bareHttpUrlRegex = /^https?:\S+$/v;
17
18
 
18
19
  /**
19
20
  * @param {'pipe'|'prefix'} canonicalForm
@@ -38,6 +39,36 @@ const encodeLinkTarget = target => {
38
39
  return encodeURI(target).replaceAll(/%25(?=[\dA-F]{2})/giv, '%');
39
40
  };
40
41
 
42
+ /**
43
+ * @param {string} description
44
+ * @param {boolean} enabled
45
+ * @returns {string|null}
46
+ */
47
+ const getBareHttpUrl = (description, enabled) => {
48
+ if (!enabled) {
49
+ return null;
50
+ }
51
+ const trimmedDescription = description.trim();
52
+ return bareHttpUrlRegex.test(trimmedDescription) && URL.canParse(trimmedDescription) ? trimmedDescription : null;
53
+ };
54
+
55
+ /**
56
+ * @param {string} target
57
+ * @returns {string}
58
+ */
59
+ const formatBareUrl = target => {
60
+ return `{@link ${encodeLinkTarget(target)}}`;
61
+ };
62
+
63
+ /**
64
+ * @param {string|undefined} bareUrl
65
+ * @param {'pipe'|'prefix'} canonicalForm
66
+ * @returns {string}
67
+ */
68
+ const getExpectedMessage = (bareUrl, canonicalForm) => {
69
+ return bareUrl ? 'Expected bare @see URL to use a {@link} tag.' : `Expected @see link to use the ${canonicalForm} form.`;
70
+ };
71
+
41
72
  /**
42
73
  * @param {string} description
43
74
  * @param {number} index
@@ -91,12 +122,15 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
91
122
  }) => {
92
123
  const {
93
124
  canonicalForm = 'pipe',
94
- enableFixer = true
125
+ enableFixer = true,
126
+ wrapBareUrls = false
95
127
  } = context.options[0] || {};
96
128
  const descriptionMatcher = canonicalForm === 'pipe' ? new RegExp(`${markdownLinkRegex.source}|${prefixLinkRegex.source}`, 'v') : new RegExp(`${markdownLinkRegex.source}|${pipeLinkRegex.source}`, 'v');
97
129
 
98
130
  /** @type {import('comment-parser').Spec[]} */
99
131
  const fixableTags = [];
132
+ /** @type {Map<import('comment-parser').Spec, string>} */
133
+ const bareUrlTags = new Map();
100
134
  for (const tag of jsdoc.tags) {
101
135
  if (tag.tag !== 'see') {
102
136
  continue;
@@ -106,6 +140,11 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
106
140
  const rawDescription = firstTokens.name ? firstTokens.name + firstTokens.postName + tagDescription : tagDescription;
107
141
  let hasAmbiguousLink = false;
108
142
  let hasNoncanonicalLink = false;
143
+ const bareUrl = getBareHttpUrl(rawDescription, wrapBareUrls);
144
+ if (bareUrl) {
145
+ bareUrlTags.set(tag, bareUrl);
146
+ hasNoncanonicalLink = true;
147
+ }
109
148
  for (const match of rawDescription.matchAll(markdownLinkRegex)) {
110
149
  const label = match[1];
111
150
  const target = match[2];
@@ -153,7 +192,8 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
153
192
  fixableTags.push(tag);
154
193
  }
155
194
  for (const [reportIdx, tag] of fixableTags.entries()) {
156
- utils.reportJSDoc(`Expected @see link to use the ${canonicalForm} form.`, {
195
+ const bareUrl = bareUrlTags.get(tag);
196
+ utils.reportJSDoc(getExpectedMessage(bareUrl, canonicalForm), {
157
197
  line: tag.source[0].number
158
198
  }, enableFixer && reportIdx === 0 ? () => {
159
199
  for (const fixableTag of fixableTags) {
@@ -163,6 +203,19 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
163
203
  firstTokens.name = '';
164
204
  firstTokens.postName = '';
165
205
  }
206
+ const fixableBareUrl = bareUrlTags.get(fixableTag);
207
+ if (fixableBareUrl) {
208
+ for (const source of fixableTag.source) {
209
+ if (!source.tokens.description.includes(fixableBareUrl)) {
210
+ continue;
211
+ }
212
+ source.tokens.description = source.tokens.description.replace(fixableBareUrl, () => {
213
+ return formatBareUrl(fixableBareUrl);
214
+ });
215
+ break;
216
+ }
217
+ continue;
218
+ }
166
219
  for (let sourceIdx = 0; sourceIdx < fixableTag.source.length; sourceIdx++) {
167
220
  if (!descriptionMatcher.test(fixableTag.source[sourceIdx].tokens.description)) {
168
221
  continue;
@@ -193,6 +246,10 @@ var _default = exports.default = (0, _iterateJsdoc.default)(({
193
246
  enableFixer: {
194
247
  description: 'Whether to enable the fixer. Defaults to `true`.',
195
248
  type: 'boolean'
249
+ },
250
+ wrapBareUrls: {
251
+ description: 'Whether to wrap an `@see` description containing only a lowercase `http:` or `https:` URL (for example, `@see https://example.com`) in a plain `{@link https://example.com}`. Defaults to `false`.',
252
+ type: 'boolean'
196
253
  }
197
254
  },
198
255
  type: 'object'
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeSeeLinks.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/normalizeSeeLinks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nconst markdownLinkRegex = /(?<!\\\\)\\[([^`\\]\\r\\n]+)\\]\\(([^`\\(\\)\\s]+)\\)/gv;\nconst prefixLinkRegex = /(?<!\\\\)\\[([^\\]\\r\\n]+)\\]\\{@link\\s+([^\\}\\s\\|]+)\\}/gv;\nconst pipeLinkRegex = /\\{@link\\s+([^\\}\\s\\|]+)\\s*\\|\\s*([^\\}\\r\\n]+)\\}/gv;\n\nconst markdownLinkAttemptRegex = /(?<!\\\\)\\[[^\\]\\r\\n]*\\]\\([^\\r\\n]*(?:\\)|$)/v;\nconst prefixLinkAttemptRegex = /(?<!\\\\)\\[[^\\]\\r\\n]*\\]\\{@link[^\\}\\r\\n]*(?:\\}|$)/v;\nconst pipeLinkAttemptRegex = /\\{@link[^\\}\\r\\n]*\\|[^\\}\\r\\n]*(?:\\}|$)/v;\n\nconst scopedPackageNameRegex = /^@[\\w.\\-]+\\/[\\w.\\-]+/v;\nconst markdownCodeSpanRegex = /(?<!\\\\)(`+)(?!`)[\\s\\S]*?(?<!`)\\1(?!`)/gv;\n\n/**\n * @param {'pipe'|'prefix'} canonicalForm\n * @param {string} label\n * @returns {boolean}\n */\nconst cannotSafelyFormatLink = (canonicalForm, label) => {\n if (!label.trim()) {\n return true;\n }\n\n if (canonicalForm === 'pipe') {\n return label.includes('}');\n }\n\n return label.includes(']');\n};\n\n/**\n * @param {string} target\n * @returns {string}\n */\nconst encodeLinkTarget = (target) => {\n return encodeURI(target).replaceAll(/%25(?=[\\dA-F]{2})/giv, '%');\n};\n\n/**\n * @param {string} description\n * @param {number} index\n * @returns {boolean}\n */\nconst isInsideMarkdownCodeSpan = (description, index) => {\n for (const match of description.matchAll(markdownCodeSpanRegex)) {\n const delimiterLength = match[1].length;\n const contentStart = match.index + delimiterLength;\n const contentEnd = match.index + match[0].length - delimiterLength;\n\n if (index >= contentStart && index < contentEnd) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * @param {'pipe'|'prefix'} canonicalForm\n * @param {string} label\n * @param {string} target\n * @returns {string}\n */\nconst formatLink = (canonicalForm, label, target) => {\n const encodedTarget = encodeLinkTarget(target);\n\n return canonicalForm === 'pipe' ?\n `{@link ${encodedTarget}|${label.trim()}}` :\n `[${label.trim()}]{@link ${encodedTarget}}`;\n};\n\n/**\n * @param {string} description\n * @param {'pipe'|'prefix'} canonicalForm\n * @returns {string}\n */\nconst normalizeDescription = (description, canonicalForm) => {\n const markdownNormalized = description.replaceAll(\n new RegExp(markdownLinkRegex, 'gv'),\n (_match, label, target) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n\n if (canonicalForm === 'pipe') {\n return markdownNormalized.replaceAll(\n new RegExp(prefixLinkRegex, 'gv'),\n (_match, label, target) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n }\n\n return markdownNormalized.replaceAll(\n new RegExp(pipeLinkRegex, 'gv'),\n (_match, target, label) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n};\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n canonicalForm = 'pipe',\n enableFixer = true,\n } = context.options[0] || {};\n\n const descriptionMatcher = canonicalForm === 'pipe' ?\n new RegExp(`${markdownLinkRegex.source}|${prefixLinkRegex.source}`, 'v') :\n new RegExp(`${markdownLinkRegex.source}|${pipeLinkRegex.source}`, 'v');\n\n /** @type {import('comment-parser').Spec[]} */\n const fixableTags = [];\n\n for (const tag of jsdoc.tags) {\n if (tag.tag !== 'see') {\n continue;\n }\n\n const firstTokens = tag.source[0].tokens;\n const tagDescription = String(utils.getTagDescription(tag));\n const rawDescription = firstTokens.name ?\n firstTokens.name + firstTokens.postName + tagDescription :\n tagDescription;\n\n let hasAmbiguousLink = false;\n let hasNoncanonicalLink = false;\n\n for (const match of rawDescription.matchAll(markdownLinkRegex)) {\n const label = match[1];\n const target = match[2];\n\n if (\n isInsideMarkdownCodeSpan(rawDescription, match.index) ||\n scopedPackageNameRegex.test(target) ||\n cannotSafelyFormatLink(canonicalForm, label)\n ) {\n hasAmbiguousLink = true;\n } else {\n hasNoncanonicalLink = true;\n }\n }\n\n for (const inlineTag of tag.inlineTags) {\n if (inlineTag.tag !== 'link' || !inlineTag.text) {\n continue;\n }\n\n if (inlineTag.format === 'space') {\n hasAmbiguousLink = true;\n continue;\n }\n\n if (cannotSafelyFormatLink(\n canonicalForm,\n inlineTag.text,\n )) {\n hasAmbiguousLink = true;\n continue;\n }\n\n if (inlineTag.format === canonicalForm) {\n continue;\n }\n\n const {\n start,\n } = /** @type {typeof inlineTag & {start: number}} */ (inlineTag);\n\n if (\n isInsideMarkdownCodeSpan(rawDescription, start) ||\n scopedPackageNameRegex.test(inlineTag.namepathOrURL)\n ) {\n hasAmbiguousLink = true;\n } else {\n hasNoncanonicalLink = true;\n }\n }\n\n const unrecognizedLinkText = rawDescription\n .replaceAll(new RegExp(markdownLinkRegex, 'gv'), '')\n .replaceAll(new RegExp(prefixLinkRegex, 'gv'), '')\n .replaceAll(new RegExp(pipeLinkRegex, 'gv'), '');\n\n hasAmbiguousLink ||= markdownLinkAttemptRegex.test(unrecognizedLinkText) ||\n prefixLinkAttemptRegex.test(unrecognizedLinkText) ||\n pipeLinkAttemptRegex.test(unrecognizedLinkText);\n\n if (hasAmbiguousLink) {\n utils.reportJSDoc('@see link cannot be safely normalized.', {\n line: tag.source[0].number,\n }, null);\n continue;\n }\n\n if (!hasNoncanonicalLink) {\n continue;\n }\n\n fixableTags.push(tag);\n }\n\n for (const [\n reportIdx,\n tag,\n ] of fixableTags.entries()) {\n utils.reportJSDoc(\n `Expected @see link to use the ${canonicalForm} form.`,\n {\n line: tag.source[0].number,\n },\n enableFixer && reportIdx === 0 ?\n () => {\n for (const fixableTag of fixableTags) {\n const firstTokens = fixableTag.source[0].tokens;\n\n if (firstTokens.name) {\n firstTokens.description = firstTokens.name +\n firstTokens.postName + firstTokens.description;\n firstTokens.name = '';\n firstTokens.postName = '';\n }\n\n for (\n let sourceIdx = 0;\n sourceIdx < fixableTag.source.length;\n sourceIdx++\n ) {\n if (!descriptionMatcher.test(\n fixableTag.source[sourceIdx].tokens.description,\n )) {\n continue;\n }\n\n utils.setTagDescription(\n fixableTag,\n descriptionMatcher,\n (description) => {\n return normalizeDescription(description, canonicalForm);\n },\n );\n }\n }\n } :\n null,\n true,\n );\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Normalizes labeled links in `@see` tags to a canonical `{@link}` form.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/normalize-see-links.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n canonicalForm: {\n description: 'The canonical `{@link}` form: `\"pipe\"` produces `{@link url|label}`, while `\"prefix\"` produces `[label]{@link url}`. Defaults to `\"pipe\"`.',\n enum: [\n 'pipe',\n 'prefix',\n ],\n type: 'string',\n },\n enableFixer: {\n description: 'Whether to enable the fixer. Defaults to `true`.',\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA8C;AAE9C,MAAM,iBAAiB,GAAG,6CAA6C;AACvE,MAAM,eAAe,GAAG,mDAAmD;AAC3E,MAAM,aAAa,GAAG,gDAAgD;AAEtE,MAAM,wBAAwB,GAAG,0CAA0C;AAC3E,MAAM,sBAAsB,GAAG,iDAAiD;AAChF,MAAM,oBAAoB,GAAG,wCAAwC;AAErE,MAAM,sBAAsB,GAAG,uBAAuB;AACtD,MAAM,qBAAqB,GAAG,yCAAyC;;AAEvE;AACA;AACA;AACA;AACA;AACA,MAAM,sBAAsB,GAAG,CAAC,aAAa,EAAE,KAAK,KAAK;EACvD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE;IACjB,OAAO,IAAI;EACb;EAEA,IAAI,aAAa,KAAK,MAAM,EAAE;IAC5B,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;EAC5B;EAEA,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC;AAC5B,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAM,gBAAgB,GAAI,MAAM,IAAK;EACnC,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,sBAAsB,EAAE,GAAG,CAAC;AAClE,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAM,wBAAwB,GAAG,CAAC,WAAW,EAAE,KAAK,KAAK;EACvD,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE;IAC/D,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM;IACvC,MAAM,YAAY,GAAG,KAAK,CAAC,KAAK,GAAG,eAAe;IAClD,MAAM,UAAU,GAAG,KAAK,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C,GACD,IAAI,EACN,IACF,CAAC;EACH;AACF,CAAC,EAAE;EACD,gBAAgB,EAAE,IAAI;EACtB,IAAI,EAAE;IACJ,IAAI,EAAE;MACJ,WAAW,EAAE,wEAAwE;MACrF,GAAG,EAAE;IACP,CAAC;IACD,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,CACN;MACE,oBAAoB,EAAE,KAAK;MAC3B,UAAU,EAAE;QACV,aAAa,EAAE;UACb,WAAW,EAAE,4IAA4I;UACzJ,IAAI,EAAE,CACJ,MAAM,EACN,QAAQ,CACT;UACD,IAAI,EAAE;QACR,CAAC;QACD,WAAW,EAAE;UACX,WAAW,EAAE,kDAAkD;UAC/D,IAAI,EAAE;QACR;MACF,CAAC;MACD,IAAI,EAAE;IACR,CAAC,CACF;IACD,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"normalizeSeeLinks.cjs","names":["iterateJsdoc"],"sources":["../../src/rules/normalizeSeeLinks.js"],"sourcesContent":["import iterateJsdoc from '../iterateJsdoc.js';\n\nconst markdownLinkRegex = /(?<!\\\\)\\[([^`\\]\\r\\n]+)\\]\\(([^`\\(\\)\\s]+)\\)/gv;\nconst prefixLinkRegex = /(?<!\\\\)\\[([^\\]\\r\\n]+)\\]\\{@link\\s+([^\\}\\s\\|]+)\\}/gv;\nconst pipeLinkRegex = /\\{@link\\s+([^\\}\\s\\|]+)\\s*\\|\\s*([^\\}\\r\\n]+)\\}/gv;\n\nconst markdownLinkAttemptRegex = /(?<!\\\\)\\[[^\\]\\r\\n]*\\]\\([^\\r\\n]*(?:\\)|$)/v;\nconst prefixLinkAttemptRegex = /(?<!\\\\)\\[[^\\]\\r\\n]*\\]\\{@link[^\\}\\r\\n]*(?:\\}|$)/v;\nconst pipeLinkAttemptRegex = /\\{@link[^\\}\\r\\n]*\\|[^\\}\\r\\n]*(?:\\}|$)/v;\n\nconst scopedPackageNameRegex = /^@[\\w.\\-]+\\/[\\w.\\-]+/v;\nconst markdownCodeSpanRegex = /(?<!\\\\)(`+)(?!`)[\\s\\S]*?(?<!`)\\1(?!`)/gv;\nconst bareHttpUrlRegex = /^https?:\\S+$/v;\n\n/**\n * @param {'pipe'|'prefix'} canonicalForm\n * @param {string} label\n * @returns {boolean}\n */\nconst cannotSafelyFormatLink = (canonicalForm, label) => {\n if (!label.trim()) {\n return true;\n }\n\n if (canonicalForm === 'pipe') {\n return label.includes('}');\n }\n\n return label.includes(']');\n};\n\n/**\n * @param {string} target\n * @returns {string}\n */\nconst encodeLinkTarget = (target) => {\n return encodeURI(target).replaceAll(/%25(?=[\\dA-F]{2})/giv, '%');\n};\n\n/**\n * @param {string} description\n * @param {boolean} enabled\n * @returns {string|null}\n */\nconst getBareHttpUrl = (description, enabled) => {\n if (!enabled) {\n return null;\n }\n\n const trimmedDescription = description.trim();\n\n return bareHttpUrlRegex.test(trimmedDescription) &&\n URL.canParse(trimmedDescription) ?\n trimmedDescription : null;\n};\n\n/**\n * @param {string} target\n * @returns {string}\n */\nconst formatBareUrl = (target) => {\n return `{@link ${encodeLinkTarget(target)}}`;\n};\n\n/**\n * @param {string|undefined} bareUrl\n * @param {'pipe'|'prefix'} canonicalForm\n * @returns {string}\n */\nconst getExpectedMessage = (bareUrl, canonicalForm) => {\n return bareUrl ?\n 'Expected bare @see URL to use a {@link} tag.' :\n `Expected @see link to use the ${canonicalForm} form.`;\n};\n\n/**\n * @param {string} description\n * @param {number} index\n * @returns {boolean}\n */\nconst isInsideMarkdownCodeSpan = (description, index) => {\n for (const match of description.matchAll(markdownCodeSpanRegex)) {\n const delimiterLength = match[1].length;\n const contentStart = match.index + delimiterLength;\n const contentEnd = match.index + match[0].length - delimiterLength;\n\n if (index >= contentStart && index < contentEnd) {\n return true;\n }\n }\n\n return false;\n};\n\n/**\n * @param {'pipe'|'prefix'} canonicalForm\n * @param {string} label\n * @param {string} target\n * @returns {string}\n */\nconst formatLink = (canonicalForm, label, target) => {\n const encodedTarget = encodeLinkTarget(target);\n\n return canonicalForm === 'pipe' ?\n `{@link ${encodedTarget}|${label.trim()}}` :\n `[${label.trim()}]{@link ${encodedTarget}}`;\n};\n\n/**\n * @param {string} description\n * @param {'pipe'|'prefix'} canonicalForm\n * @returns {string}\n */\nconst normalizeDescription = (description, canonicalForm) => {\n const markdownNormalized = description.replaceAll(\n new RegExp(markdownLinkRegex, 'gv'),\n (_match, label, target) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n\n if (canonicalForm === 'pipe') {\n return markdownNormalized.replaceAll(\n new RegExp(prefixLinkRegex, 'gv'),\n (_match, label, target) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n }\n\n return markdownNormalized.replaceAll(\n new RegExp(pipeLinkRegex, 'gv'),\n (_match, target, label) => {\n return formatLink(canonicalForm, label, target);\n },\n );\n};\n\nexport default iterateJsdoc(({\n context,\n jsdoc,\n utils,\n}) => {\n const {\n canonicalForm = 'pipe',\n enableFixer = true,\n wrapBareUrls = false,\n } = context.options[0] || {};\n\n const descriptionMatcher = canonicalForm === 'pipe' ?\n new RegExp(`${markdownLinkRegex.source}|${prefixLinkRegex.source}`, 'v') :\n new RegExp(`${markdownLinkRegex.source}|${pipeLinkRegex.source}`, 'v');\n\n /** @type {import('comment-parser').Spec[]} */\n const fixableTags = [];\n /** @type {Map<import('comment-parser').Spec, string>} */\n const bareUrlTags = new Map();\n\n for (const tag of jsdoc.tags) {\n if (tag.tag !== 'see') {\n continue;\n }\n\n const firstTokens = tag.source[0].tokens;\n const tagDescription = String(utils.getTagDescription(tag));\n const rawDescription = firstTokens.name ?\n firstTokens.name + firstTokens.postName + tagDescription :\n tagDescription;\n\n let hasAmbiguousLink = false;\n let hasNoncanonicalLink = false;\n const bareUrl = getBareHttpUrl(rawDescription, wrapBareUrls);\n\n if (bareUrl) {\n bareUrlTags.set(tag, bareUrl);\n hasNoncanonicalLink = true;\n }\n\n for (const match of rawDescription.matchAll(markdownLinkRegex)) {\n const label = match[1];\n const target = match[2];\n\n if (\n isInsideMarkdownCodeSpan(rawDescription, match.index) ||\n scopedPackageNameRegex.test(target) ||\n cannotSafelyFormatLink(canonicalForm, label)\n ) {\n hasAmbiguousLink = true;\n } else {\n hasNoncanonicalLink = true;\n }\n }\n\n for (const inlineTag of tag.inlineTags) {\n if (inlineTag.tag !== 'link' || !inlineTag.text) {\n continue;\n }\n\n if (inlineTag.format === 'space') {\n hasAmbiguousLink = true;\n continue;\n }\n\n if (cannotSafelyFormatLink(\n canonicalForm,\n inlineTag.text,\n )) {\n hasAmbiguousLink = true;\n continue;\n }\n\n if (inlineTag.format === canonicalForm) {\n continue;\n }\n\n const {\n start,\n } = /** @type {typeof inlineTag & {start: number}} */ (inlineTag);\n\n if (\n isInsideMarkdownCodeSpan(rawDescription, start) ||\n scopedPackageNameRegex.test(inlineTag.namepathOrURL)\n ) {\n hasAmbiguousLink = true;\n } else {\n hasNoncanonicalLink = true;\n }\n }\n\n const unrecognizedLinkText = rawDescription\n .replaceAll(new RegExp(markdownLinkRegex, 'gv'), '')\n .replaceAll(new RegExp(prefixLinkRegex, 'gv'), '')\n .replaceAll(new RegExp(pipeLinkRegex, 'gv'), '');\n\n hasAmbiguousLink ||= markdownLinkAttemptRegex.test(unrecognizedLinkText) ||\n prefixLinkAttemptRegex.test(unrecognizedLinkText) ||\n pipeLinkAttemptRegex.test(unrecognizedLinkText);\n\n if (hasAmbiguousLink) {\n utils.reportJSDoc('@see link cannot be safely normalized.', {\n line: tag.source[0].number,\n }, null);\n continue;\n }\n\n if (!hasNoncanonicalLink) {\n continue;\n }\n\n fixableTags.push(tag);\n }\n\n for (const [\n reportIdx,\n tag,\n ] of fixableTags.entries()) {\n const bareUrl = bareUrlTags.get(tag);\n\n utils.reportJSDoc(\n getExpectedMessage(bareUrl, canonicalForm),\n {\n line: tag.source[0].number,\n },\n enableFixer && reportIdx === 0 ?\n () => {\n for (const fixableTag of fixableTags) {\n const firstTokens = fixableTag.source[0].tokens;\n\n if (firstTokens.name) {\n firstTokens.description = firstTokens.name +\n firstTokens.postName + firstTokens.description;\n firstTokens.name = '';\n firstTokens.postName = '';\n }\n\n const fixableBareUrl = bareUrlTags.get(fixableTag);\n\n if (fixableBareUrl) {\n for (const source of fixableTag.source) {\n if (!source.tokens.description.includes(fixableBareUrl)) {\n continue;\n }\n\n source.tokens.description = source.tokens.description.replace(\n fixableBareUrl,\n () => {\n return formatBareUrl(fixableBareUrl);\n },\n );\n break;\n }\n\n continue;\n }\n\n for (\n let sourceIdx = 0;\n sourceIdx < fixableTag.source.length;\n sourceIdx++\n ) {\n if (!descriptionMatcher.test(\n fixableTag.source[sourceIdx].tokens.description,\n )) {\n continue;\n }\n\n utils.setTagDescription(\n fixableTag,\n descriptionMatcher,\n (description) => {\n return normalizeDescription(description, canonicalForm);\n },\n );\n }\n }\n } :\n null,\n true,\n );\n }\n}, {\n iterateAllJsdocs: true,\n meta: {\n docs: {\n description: 'Normalizes labeled links in `@see` tags to a canonical `{@link}` form.',\n url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/normalize-see-links.md#repos-sticky-header',\n },\n fixable: 'code',\n schema: [\n {\n additionalProperties: false,\n properties: {\n canonicalForm: {\n description: 'The canonical `{@link}` form: `\"pipe\"` produces `{@link url|label}`, while `\"prefix\"` produces `[label]{@link url}`. Defaults to `\"pipe\"`.',\n enum: [\n 'pipe',\n 'prefix',\n ],\n type: 'string',\n },\n enableFixer: {\n description: 'Whether to enable the fixer. Defaults to `true`.',\n type: 'boolean',\n },\n wrapBareUrls: {\n description: 'Whether to wrap an `@see` description containing only a lowercase `http:` or `https:` URL (for example, `@see https://example.com`) in a plain `{@link https://example.com}`. Defaults to `false`.',\n type: 'boolean',\n },\n },\n type: 'object',\n },\n ],\n type: 'suggestion',\n },\n});\n"],"mappings":";;;;;;AAAA;AAA8C;AAE9C,MAAM,iBAAiB,GAAG,6CAA6C;AACvE,MAAM,eAAe,GAAG,mDAAmD;AAC3E,MAAM,aAAa,GAAG,gDAAgD;AAEtE,M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AAG,EAAE;IACP,CAAC;IACD,OAAO,EAAE,MAAM;IACf,MAAM,EAAE,CACN;MACE,oBAAoB,EAAE,KAAK;MAC3B,UAAU,EAAE;QACV,aAAa,EAAE;UACb,WAAW,EAAE,4IAA4I;UACzJ,IAAI,EAAE,CACJ,MAAM,EACN,QAAQ,CACT;UACD,IAAI,EAAE;QACR,CAAC;QACD,WAAW,EAAE;UACX,WAAW,EAAE,kDAAkD;UAC/D,IAAI,EAAE;QACR,CAAC;QACD,YAAY,EAAE;UACZ,WAAW,EAAE,oMAAoM;UACjN,IAAI,EAAE;QACR;MACF,CAAC;MACD,IAAI,EAAE;IACR,CAAC,CACF;IACD,IAAI,EAAE;EACR;AACF,CAAC,CAAC;AAAA","ignoreList":[]}
package/dist/rules.d.ts CHANGED
@@ -1305,6 +1305,10 @@ export interface Rules {
1305
1305
  * Whether to enable the fixer. Defaults to `true`.
1306
1306
  */
1307
1307
  enableFixer?: boolean;
1308
+ /**
1309
+ * Whether to wrap an `@see` description containing only a lowercase `http:` or `https:` URL (for example, `@see https://example.com`) in a plain `{@link https://example.com}`. Defaults to `false`.
1310
+ */
1311
+ wrapBareUrls?: boolean;
1308
1312
  }
1309
1313
  ];
1310
1314
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "http://gajus.com"
6
6
  },
7
7
  "dependencies": {
8
- "@es-joy/jsdoccomment": "~0.88.0",
8
+ "@es-joy/jsdoccomment": "~0.89.0",
9
9
  "@es-joy/resolve.exports": "1.2.0",
10
10
  "are-docs-informative": "^0.0.2",
11
11
  "comment-parser": "1.4.7",
@@ -17,13 +17,13 @@
17
17
  "object-deep-merge": "^2.0.1",
18
18
  "parse-imports-exports": "^0.2.4",
19
19
  "semver": "^7.8.5",
20
- "spdx-expression-parse": "^4.0.0",
20
+ "spdx-expression-parse": "^5.0.0",
21
21
  "to-valid-identifier": "^1.0.0"
22
22
  },
23
23
  "description": "JSDoc linting rules for ESLint.",
24
24
  "devDependencies": {
25
- "@arethetypeswrong/cli": "^0.18.4",
26
- "@babel/cli": "8.0.1",
25
+ "@arethetypeswrong/cli": "^0.18.5",
26
+ "@babel/cli": "8.0.4",
27
27
  "@babel/core": "8.0.1",
28
28
  "@babel/eslint-parser": "8.0.1",
29
29
  "@babel/plugin-transform-flow-strip-types": "8.0.1",
@@ -42,18 +42,18 @@
42
42
  "@types/estree": "^1.0.9",
43
43
  "@types/json-schema": "^7.0.15",
44
44
  "@types/mocha": "^10.0.10",
45
- "@types/node": "^26.1.0",
45
+ "@types/node": "^26.1.1",
46
46
  "@types/semver": "^7.7.1",
47
47
  "@types/spdx-expression-parse": "^4.0.0",
48
- "@typescript-eslint/types": "8.62.1",
48
+ "@typescript-eslint/types": "8.65.0",
49
49
  "babel-plugin-add-module-exports": "^1.0.4",
50
50
  "babel-plugin-istanbul": "^8.0.0",
51
51
  "babel-plugin-transform-import-meta": "^3.0.0",
52
- "c8": "^11.0.0",
52
+ "c8": "^12.0.0",
53
53
  "camelcase": "^9.0.0",
54
54
  "chai": "^6.2.2",
55
55
  "decamelize": "^6.0.1",
56
- "eslint": "10.6.0",
56
+ "eslint": "10.7.0",
57
57
  "eslint-config-canonical": "^47.4.2",
58
58
  "gitdown": "^4.1.1",
59
59
  "glob": "^13.0.6",
@@ -62,18 +62,18 @@
62
62
  "jsdoc-type-pratt-parser": "^7.2.0",
63
63
  "json-schema": "^0.4.0",
64
64
  "json-schema-to-typescript": "^15.0.4",
65
- "lint-staged": "^17.0.8",
65
+ "lint-staged": "^17.2.0",
66
66
  "mocha": "^11.7.6",
67
67
  "open-editor": "^6.0.0",
68
68
  "playwright": "^1.61.1",
69
69
  "replace": "^1.2.2",
70
70
  "rimraf": "^6.1.3",
71
71
  "rollup": "^4.62.2",
72
- "semantic-release": "^25.0.5",
73
- "sinon": "^22.0.0",
72
+ "semantic-release": "^25.0.8",
73
+ "sinon": "^22.1.0",
74
74
  "ts-api-utils": "^2.5.0",
75
75
  "typescript": "5.9.3",
76
- "typescript-eslint": "8.62.1"
76
+ "typescript-eslint": "8.65.0"
77
77
  },
78
78
  "engines": {
79
79
  "node": "^22.13.0 || >=24"
@@ -179,5 +179,5 @@
179
179
  "test-cov": "TIMING=1 c8 --reporter text pnpm run test-no-cov",
180
180
  "test-index": "pnpm run test-no-cov test/rules/index.js"
181
181
  },
182
- "version": "63.1.0"
182
+ "version": "63.2.1"
183
183
  }
@@ -10,6 +10,7 @@ const pipeLinkAttemptRegex = /\{@link[^\}\r\n]*\|[^\}\r\n]*(?:\}|$)/v;
10
10
 
11
11
  const scopedPackageNameRegex = /^@[\w.\-]+\/[\w.\-]+/v;
12
12
  const markdownCodeSpanRegex = /(?<!\\)(`+)(?!`)[\s\S]*?(?<!`)\1(?!`)/gv;
13
+ const bareHttpUrlRegex = /^https?:\S+$/v;
13
14
 
14
15
  /**
15
16
  * @param {'pipe'|'prefix'} canonicalForm
@@ -36,6 +37,42 @@ const encodeLinkTarget = (target) => {
36
37
  return encodeURI(target).replaceAll(/%25(?=[\dA-F]{2})/giv, '%');
37
38
  };
38
39
 
40
+ /**
41
+ * @param {string} description
42
+ * @param {boolean} enabled
43
+ * @returns {string|null}
44
+ */
45
+ const getBareHttpUrl = (description, enabled) => {
46
+ if (!enabled) {
47
+ return null;
48
+ }
49
+
50
+ const trimmedDescription = description.trim();
51
+
52
+ return bareHttpUrlRegex.test(trimmedDescription) &&
53
+ URL.canParse(trimmedDescription) ?
54
+ trimmedDescription : null;
55
+ };
56
+
57
+ /**
58
+ * @param {string} target
59
+ * @returns {string}
60
+ */
61
+ const formatBareUrl = (target) => {
62
+ return `{@link ${encodeLinkTarget(target)}}`;
63
+ };
64
+
65
+ /**
66
+ * @param {string|undefined} bareUrl
67
+ * @param {'pipe'|'prefix'} canonicalForm
68
+ * @returns {string}
69
+ */
70
+ const getExpectedMessage = (bareUrl, canonicalForm) => {
71
+ return bareUrl ?
72
+ 'Expected bare @see URL to use a {@link} tag.' :
73
+ `Expected @see link to use the ${canonicalForm} form.`;
74
+ };
75
+
39
76
  /**
40
77
  * @param {string} description
41
78
  * @param {number} index
@@ -107,6 +144,7 @@ export default iterateJsdoc(({
107
144
  const {
108
145
  canonicalForm = 'pipe',
109
146
  enableFixer = true,
147
+ wrapBareUrls = false,
110
148
  } = context.options[0] || {};
111
149
 
112
150
  const descriptionMatcher = canonicalForm === 'pipe' ?
@@ -115,6 +153,8 @@ export default iterateJsdoc(({
115
153
 
116
154
  /** @type {import('comment-parser').Spec[]} */
117
155
  const fixableTags = [];
156
+ /** @type {Map<import('comment-parser').Spec, string>} */
157
+ const bareUrlTags = new Map();
118
158
 
119
159
  for (const tag of jsdoc.tags) {
120
160
  if (tag.tag !== 'see') {
@@ -129,6 +169,12 @@ export default iterateJsdoc(({
129
169
 
130
170
  let hasAmbiguousLink = false;
131
171
  let hasNoncanonicalLink = false;
172
+ const bareUrl = getBareHttpUrl(rawDescription, wrapBareUrls);
173
+
174
+ if (bareUrl) {
175
+ bareUrlTags.set(tag, bareUrl);
176
+ hasNoncanonicalLink = true;
177
+ }
132
178
 
133
179
  for (const match of rawDescription.matchAll(markdownLinkRegex)) {
134
180
  const label = match[1];
@@ -208,8 +254,10 @@ export default iterateJsdoc(({
208
254
  reportIdx,
209
255
  tag,
210
256
  ] of fixableTags.entries()) {
257
+ const bareUrl = bareUrlTags.get(tag);
258
+
211
259
  utils.reportJSDoc(
212
- `Expected @see link to use the ${canonicalForm} form.`,
260
+ getExpectedMessage(bareUrl, canonicalForm),
213
261
  {
214
262
  line: tag.source[0].number,
215
263
  },
@@ -225,6 +273,26 @@ export default iterateJsdoc(({
225
273
  firstTokens.postName = '';
226
274
  }
227
275
 
276
+ const fixableBareUrl = bareUrlTags.get(fixableTag);
277
+
278
+ if (fixableBareUrl) {
279
+ for (const source of fixableTag.source) {
280
+ if (!source.tokens.description.includes(fixableBareUrl)) {
281
+ continue;
282
+ }
283
+
284
+ source.tokens.description = source.tokens.description.replace(
285
+ fixableBareUrl,
286
+ () => {
287
+ return formatBareUrl(fixableBareUrl);
288
+ },
289
+ );
290
+ break;
291
+ }
292
+
293
+ continue;
294
+ }
295
+
228
296
  for (
229
297
  let sourceIdx = 0;
230
298
  sourceIdx < fixableTag.source.length;
@@ -274,6 +342,10 @@ export default iterateJsdoc(({
274
342
  description: 'Whether to enable the fixer. Defaults to `true`.',
275
343
  type: 'boolean',
276
344
  },
345
+ wrapBareUrls: {
346
+ description: 'Whether to wrap an `@see` description containing only a lowercase `http:` or `https:` URL (for example, `@see https://example.com`) in a plain `{@link https://example.com}`. Defaults to `false`.',
347
+ type: 'boolean',
348
+ },
277
349
  },
278
350
  type: 'object',
279
351
  },
package/src/rules.d.ts CHANGED
@@ -1305,6 +1305,10 @@ export interface Rules {
1305
1305
  * Whether to enable the fixer. Defaults to `true`.
1306
1306
  */
1307
1307
  enableFixer?: boolean;
1308
+ /**
1309
+ * Whether to wrap an `@see` description containing only a lowercase `http:` or `https:` URL (for example, `@see https://example.com`) in a plain `{@link https://example.com}`. Defaults to `false`.
1310
+ */
1311
+ wrapBareUrls?: boolean;
1308
1312
  }
1309
1313
  ];
1310
1314