@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 +5 -0
- package/build/index.js +55 -10
- package/build/index.js.map +2 -2
- package/build/rules/helpers.d.ts +13 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
[](https://www.npmjs.org/package/@diplodoc/yfmlint)
|
|
2
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
3
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
4
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
5
|
+
[](https://sonarcloud.io/summary/overall?id=diplodoc-platform_yfmlint)
|
|
6
|
+
[](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
|
|
21497
|
-
context
|
|
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
|
|
21515
|
-
context
|
|
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
|
|
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: ${
|
|
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
|
|
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
|
|
21746
|
-
context
|
|
21790
|
+
lineNumber,
|
|
21791
|
+
context
|
|
21747
21792
|
});
|
|
21748
21793
|
});
|
|
21749
21794
|
}
|