Skip to content

Commit

Permalink
Merge pull request #48 from UmbrellaDocs/handle-asciidoc
Browse files Browse the repository at this point in the history
Check AsciiDoc hyperlinks
  • Loading branch information
gaurav-nelson authored May 12, 2024
2 parents 45a0cf9 + 9f40982 commit 4e74c13
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 135 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ program
if (linkStatusObj.status === "error") {
if (cmd.json) {
results.diagnostics.push({
message: linkStatusObj.error_message,
message: `Connot reach ${linkStatusObj.link}. Status: ${linkStatusObj.status_code}${linkStatusObj.error_message ? ` ${linkStatusObj.error_message}` : ''}`,
location: {
path: currentFile,
range: {
Expand All @@ -67,7 +67,7 @@ program
spinner.stop();
console.log(
kleur.red(
`💥 ${currentFile} - Line ${linkStatusObj.line_number}: ${linkStatusObj.error_message}`
`🚫 ${currentFile}, ${linkStatusObj.link} , ${linkStatusObj.status_code}, ${linkStatusObj.line_number}, ${linkStatusObj.error_message}`
)
);
spinner.start(`Checking ${currentFile}...\n`);
Expand Down
36 changes: 36 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,39 @@ test("linkspector should add back the removed duplicates when returning the resu
expect(results[2].status).toBe("alive");
expect(results[3].status).toBe("error");
});

test(" linkspector should check hyperlinks in AsciiDoc files", async () => {
let hasErrorLinks = false;
let currentFile = ""; // Variable to store the current file name
let results = []; // Array to store the results if json is true

for await (const { file, result } of linkspector(
"./test/fixtures/asciidoc/hyperlinks/hyperlinksTest.yml",
cmd
)) {
currentFile = file;
for (const linkStatusObj of result) {
if (cmd.json) {
results.push({
file: currentFile,
link: linkStatusObj.link,
status_code: linkStatusObj.status_code,
line_number: linkStatusObj.line_number,
position: linkStatusObj.position,
status: linkStatusObj.status,
error_message: linkStatusObj.error_message,
});
}
if (linkStatusObj.status === "error") {
hasErrorLinks = true;
}
}
}

expect(hasErrorLinks).toBe(true);
expect(results.length).toBe(4);
expect(results[0].status).toBe("error");
expect(results[1].status).toBe("alive");
expect(results[2].status).toBe("error");
expect(results[3].status).toBe("alive");
});
100 changes: 0 additions & 100 deletions lib/extract-asciidoc-hyperlinks.js

This file was deleted.

Loading

0 comments on commit 4e74c13

Please sign in to comment.