Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check AsciiDoc hyperlinks #48

Merged
merged 3 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading