@diplodoc/yfmlint 1.3.5 → 1.4.0
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/build/index.js +94 -43
- package/build/index.js.map +2 -2
- package/build/rules/helpers.d.ts +38 -0
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -21490,6 +21490,27 @@ function validateLineNumberAndGetFilePath(params2, rawLineNumber) {
|
|
|
21490
21490
|
const filePath = (env == null ? void 0 : env.path) || params2.name;
|
|
21491
21491
|
return { lineNumber, filePath };
|
|
21492
21492
|
}
|
|
21493
|
+
function resolveIncludeSource(params2, rawLineNumber, token, parentToken) {
|
|
21494
|
+
var _a, _b, _c, _d;
|
|
21495
|
+
const sourceFile = ((_a = token == null ? void 0 : token.meta) == null ? void 0 : _a.sourceFile) || ((_b = parentToken == null ? void 0 : parentToken.meta) == null ? void 0 : _b.sourceFile);
|
|
21496
|
+
const includeChain = ((_c = token == null ? void 0 : token.meta) == null ? void 0 : _c.includeChain) || ((_d = parentToken == null ? void 0 : parentToken.meta) == null ? void 0 : _d.includeChain);
|
|
21497
|
+
if (!sourceFile || !(includeChain == null ? void 0 : includeChain.length)) {
|
|
21498
|
+
return null;
|
|
21499
|
+
}
|
|
21500
|
+
const mainFileLine = includeChain[0].line;
|
|
21501
|
+
const lineNumber = Math.min(Math.max(1, mainFileLine), params2.lines.length);
|
|
21502
|
+
return {
|
|
21503
|
+
lineNumber,
|
|
21504
|
+
sourceFile,
|
|
21505
|
+
sourceLineNumber: rawLineNumber || 1,
|
|
21506
|
+
includeChain
|
|
21507
|
+
};
|
|
21508
|
+
}
|
|
21509
|
+
function formatIncludeChain(info, brokenTarget) {
|
|
21510
|
+
const parts = info.includeChain.map((entry) => `${entry.file}:${entry.line}`);
|
|
21511
|
+
parts.push(`${info.sourceFile}:${info.sourceLineNumber}`);
|
|
21512
|
+
return `${parts.join(" \u2192 ")} \u219B ${brokenTarget}`;
|
|
21513
|
+
}
|
|
21493
21514
|
function createContextWithFileInfo(baseContext, filePath, paramsName) {
|
|
21494
21515
|
const parts = [baseContext];
|
|
21495
21516
|
if (filePath !== paramsName) {
|
|
@@ -21507,19 +21528,28 @@ function findLinksInInlineTokens(params2, ruleName, onError, handler) {
|
|
|
21507
21528
|
handler(linkToken, inline);
|
|
21508
21529
|
} else {
|
|
21509
21530
|
const rawLineNumber = link.lineNumber || inline.lineNumber;
|
|
21510
|
-
const
|
|
21531
|
+
const includeSource = resolveIncludeSource(
|
|
21511
21532
|
params2,
|
|
21512
|
-
rawLineNumber
|
|
21513
|
-
|
|
21514
|
-
|
|
21515
|
-
link.line || inline.line,
|
|
21516
|
-
filePath,
|
|
21517
|
-
params2.name
|
|
21533
|
+
rawLineNumber,
|
|
21534
|
+
link,
|
|
21535
|
+
inline
|
|
21518
21536
|
);
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
context
|
|
21522
|
-
|
|
21537
|
+
if (includeSource) {
|
|
21538
|
+
const href = linkToken.attrGet("href") || "";
|
|
21539
|
+
const context = formatIncludeChain(includeSource, href);
|
|
21540
|
+
onError({ lineNumber: includeSource.lineNumber, context });
|
|
21541
|
+
} else {
|
|
21542
|
+
const { lineNumber, filePath } = validateLineNumberAndGetFilePath(
|
|
21543
|
+
params2,
|
|
21544
|
+
rawLineNumber
|
|
21545
|
+
);
|
|
21546
|
+
const context = createContextWithFileInfo(
|
|
21547
|
+
link.line || inline.line,
|
|
21548
|
+
filePath,
|
|
21549
|
+
params2.name
|
|
21550
|
+
);
|
|
21551
|
+
onError({ lineNumber, context });
|
|
21552
|
+
}
|
|
21523
21553
|
}
|
|
21524
21554
|
}
|
|
21525
21555
|
});
|
|
@@ -21535,19 +21565,28 @@ function findImagesInInlineTokens(params2, ruleName, onError, handler) {
|
|
|
21535
21565
|
handler(imageToken, inline);
|
|
21536
21566
|
} else {
|
|
21537
21567
|
const rawLineNumber = image.lineNumber || inline.lineNumber;
|
|
21538
|
-
const
|
|
21568
|
+
const includeSource = resolveIncludeSource(
|
|
21539
21569
|
params2,
|
|
21540
|
-
rawLineNumber
|
|
21541
|
-
|
|
21542
|
-
|
|
21543
|
-
image.line || inline.line,
|
|
21544
|
-
filePath,
|
|
21545
|
-
params2.name
|
|
21570
|
+
rawLineNumber,
|
|
21571
|
+
image,
|
|
21572
|
+
inline
|
|
21546
21573
|
);
|
|
21547
|
-
|
|
21548
|
-
|
|
21549
|
-
context
|
|
21550
|
-
|
|
21574
|
+
if (includeSource) {
|
|
21575
|
+
const src = imageToken.attrGet("src") || "";
|
|
21576
|
+
const context = formatIncludeChain(includeSource, src);
|
|
21577
|
+
onError({ lineNumber: includeSource.lineNumber, context });
|
|
21578
|
+
} else {
|
|
21579
|
+
const { lineNumber, filePath } = validateLineNumberAndGetFilePath(
|
|
21580
|
+
params2,
|
|
21581
|
+
rawLineNumber
|
|
21582
|
+
);
|
|
21583
|
+
const context = createContextWithFileInfo(
|
|
21584
|
+
image.line || inline.line,
|
|
21585
|
+
filePath,
|
|
21586
|
+
params2.name
|
|
21587
|
+
);
|
|
21588
|
+
onError({ lineNumber, context });
|
|
21589
|
+
}
|
|
21551
21590
|
}
|
|
21552
21591
|
}
|
|
21553
21592
|
});
|
|
@@ -21605,21 +21644,26 @@ var yfm003 = {
|
|
|
21605
21644
|
if (reason) {
|
|
21606
21645
|
const reasonDescription = typeof reason === "string" && REASON_DESCRIPTION[reason] ? `Reason: ${REASON_DESCRIPTION[reason]}` : "";
|
|
21607
21646
|
const rawLineNumber = linkToken.lineNumber || inline.lineNumber;
|
|
21608
|
-
const
|
|
21647
|
+
const href = linkToken.attrGet("href") || "";
|
|
21648
|
+
const includeSource = resolveIncludeSource(
|
|
21609
21649
|
params2,
|
|
21610
|
-
rawLineNumber
|
|
21650
|
+
rawLineNumber,
|
|
21651
|
+
linkToken,
|
|
21652
|
+
inline
|
|
21611
21653
|
);
|
|
21612
|
-
|
|
21613
|
-
|
|
21614
|
-
reasonDescription
|
|
21615
|
-
|
|
21616
|
-
|
|
21617
|
-
|
|
21618
|
-
|
|
21619
|
-
|
|
21620
|
-
|
|
21621
|
-
|
|
21622
|
-
|
|
21654
|
+
if (includeSource) {
|
|
21655
|
+
const chain = formatIncludeChain(includeSource, href);
|
|
21656
|
+
const context = [chain, reasonDescription].filter(Boolean).join("; ");
|
|
21657
|
+
onError({ lineNumber: includeSource.lineNumber, context });
|
|
21658
|
+
} else {
|
|
21659
|
+
const { lineNumber } = validateLineNumberAndGetFilePath(params2, rawLineNumber);
|
|
21660
|
+
const context = [
|
|
21661
|
+
`Unreachable link: "${href}"`,
|
|
21662
|
+
reasonDescription,
|
|
21663
|
+
`Line: ${rawLineNumber}`
|
|
21664
|
+
].filter(Boolean).join("; ");
|
|
21665
|
+
onError({ lineNumber, context });
|
|
21666
|
+
}
|
|
21623
21667
|
}
|
|
21624
21668
|
});
|
|
21625
21669
|
}
|
|
@@ -21781,15 +21825,22 @@ var yfm010 = {
|
|
|
21781
21825
|
return;
|
|
21782
21826
|
}
|
|
21783
21827
|
findLinksInInlineTokens(params2, "YFM010", onError, (linkToken, inline) => {
|
|
21784
|
-
const
|
|
21828
|
+
const href = linkToken.attrGet("href") || "";
|
|
21785
21829
|
const rawLineNumber = linkToken.lineNumber || inline.lineNumber;
|
|
21786
|
-
const
|
|
21787
|
-
|
|
21788
|
-
|
|
21789
|
-
|
|
21790
|
-
|
|
21791
|
-
|
|
21792
|
-
|
|
21830
|
+
const includeSource = resolveIncludeSource(
|
|
21831
|
+
params2,
|
|
21832
|
+
rawLineNumber,
|
|
21833
|
+
linkToken,
|
|
21834
|
+
inline
|
|
21835
|
+
);
|
|
21836
|
+
if (includeSource) {
|
|
21837
|
+
const context = formatIncludeChain(includeSource, href);
|
|
21838
|
+
onError({ lineNumber: includeSource.lineNumber, context });
|
|
21839
|
+
} else {
|
|
21840
|
+
const { lineNumber } = validateLineNumberAndGetFilePath(params2, rawLineNumber);
|
|
21841
|
+
const context = `Unreachable autotitle anchor: "${href}"; Line: ${rawLineNumber}`;
|
|
21842
|
+
onError({ lineNumber, context });
|
|
21843
|
+
}
|
|
21793
21844
|
});
|
|
21794
21845
|
}
|
|
21795
21846
|
};
|