@diplodoc/yfmlint 1.3.4 → 1.3.5

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.
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
1
  [![NPM version](https://img.shields.io/npm/v/@diplodoc/yfmlint.svg?style=flat)](https://www.npmjs.org/package/@diplodoc/yfmlint)
2
+ [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=alert_status)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
3
+ [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=coverage)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
4
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
5
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=reliability_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
6
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=diplodoc-platform_yfmlint&metric=security_rating)](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
2
7
 
3
8
  # YFM syntax linter
4
9
 
package/build/index.js CHANGED
@@ -21483,6 +21483,20 @@ var yfm001 = {
21483
21483
  };
21484
21484
 
21485
21485
  // src/rules/helpers.ts
21486
+ function validateLineNumberAndGetFilePath(params2, rawLineNumber) {
21487
+ const linesCount = params2.lines.length;
21488
+ const lineNumber = Math.min(Math.max(1, rawLineNumber || 1), linesCount);
21489
+ const env = params2.parsers.markdownit.env;
21490
+ const filePath = (env == null ? void 0 : env.path) || params2.name;
21491
+ return { lineNumber, filePath };
21492
+ }
21493
+ function createContextWithFileInfo(baseContext, filePath, paramsName) {
21494
+ const parts = [baseContext];
21495
+ if (filePath !== paramsName) {
21496
+ parts.push(`File: ${filePath}`);
21497
+ }
21498
+ return parts.filter(Boolean).join("; ");
21499
+ }
21486
21500
  function findLinksInInlineTokens(params2, ruleName, onError, handler) {
21487
21501
  params2.parsers.markdownit.tokens.filter((token) => token.type === "inline").forEach((inline) => {
21488
21502
  var _a;
@@ -21492,9 +21506,19 @@ function findLinksInInlineTokens(params2, ruleName, onError, handler) {
21492
21506
  if (handler) {
21493
21507
  handler(linkToken, inline);
21494
21508
  } else {
21509
+ const rawLineNumber = link.lineNumber || inline.lineNumber;
21510
+ const { lineNumber, filePath } = validateLineNumberAndGetFilePath(
21511
+ params2,
21512
+ rawLineNumber
21513
+ );
21514
+ const context = createContextWithFileInfo(
21515
+ link.line || inline.line,
21516
+ filePath,
21517
+ params2.name
21518
+ );
21495
21519
  onError({
21496
- lineNumber: link.lineNumber || inline.lineNumber,
21497
- context: link.line || inline.line
21520
+ lineNumber,
21521
+ context
21498
21522
  });
21499
21523
  }
21500
21524
  }
@@ -21510,9 +21534,19 @@ function findImagesInInlineTokens(params2, ruleName, onError, handler) {
21510
21534
  if (handler) {
21511
21535
  handler(imageToken, inline);
21512
21536
  } else {
21537
+ const rawLineNumber = image.lineNumber || inline.lineNumber;
21538
+ const { lineNumber, filePath } = validateLineNumberAndGetFilePath(
21539
+ params2,
21540
+ rawLineNumber
21541
+ );
21542
+ const context = createContextWithFileInfo(
21543
+ image.line || inline.line,
21544
+ filePath,
21545
+ params2.name
21546
+ );
21513
21547
  onError({
21514
- lineNumber: image.lineNumber || inline.lineNumber,
21515
- context: image.line || inline.line
21548
+ lineNumber,
21549
+ context
21516
21550
  });
21517
21551
  }
21518
21552
  }
@@ -21570,13 +21604,20 @@ var yfm003 = {
21570
21604
  const reason = linkToken.attrGet("YFM003");
21571
21605
  if (reason) {
21572
21606
  const reasonDescription = typeof reason === "string" && REASON_DESCRIPTION[reason] ? `Reason: ${REASON_DESCRIPTION[reason]}` : "";
21573
- const context = [
21607
+ const rawLineNumber = linkToken.lineNumber || inline.lineNumber;
21608
+ const { lineNumber, filePath } = validateLineNumberAndGetFilePath(
21609
+ params2,
21610
+ rawLineNumber
21611
+ );
21612
+ const baseContext = [
21574
21613
  `Unreachable link: "${linkToken.attrGet("href")}"`,
21575
21614
  reasonDescription,
21576
- `Line: ${linkToken.lineNumber || inline.lineNumber}`
21615
+ `Line: ${rawLineNumber}`
21616
+ // Show original line number for debugging
21577
21617
  ].filter(Boolean).join("; ");
21618
+ const context = createContextWithFileInfo(baseContext, filePath, params2.name);
21578
21619
  onError({
21579
- lineNumber: linkToken.lineNumber || inline.lineNumber,
21620
+ lineNumber,
21580
21621
  context
21581
21622
  });
21582
21623
  }
@@ -21739,11 +21780,15 @@ var yfm010 = {
21739
21780
  if (!config) {
21740
21781
  return;
21741
21782
  }
21742
- findLinksInInlineTokens(params2, "YFM010", onError, (linkToken) => {
21783
+ findLinksInInlineTokens(params2, "YFM010", onError, (linkToken, inline) => {
21743
21784
  const autotitleAnchorError = `[Unreachable autotitle anchor: "${linkToken.attrGet("href")}"]`;
21785
+ const rawLineNumber = linkToken.lineNumber || inline.lineNumber;
21786
+ const { lineNumber, filePath } = validateLineNumberAndGetFilePath(params2, rawLineNumber);
21787
+ const baseContext = [autotitleAnchorError, linkToken.line || ""].join(" ");
21788
+ const context = createContextWithFileInfo(baseContext, filePath, params2.name);
21744
21789
  onError({
21745
- lineNumber: linkToken.lineNumber,
21746
- context: autotitleAnchorError + " " + (linkToken.line || "")
21790
+ lineNumber,
21791
+ context
21747
21792
  });
21748
21793
  });
21749
21794
  }