Skip to content

Commit

Permalink
Allow exceptions to be configured (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 authored Dec 27, 2022
1 parent 5763159 commit 207b296
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions no-generic-link-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ module.exports = {
tags: ["accessibility", "links"],
function: function GH002(params, onError) {
// markdown syntax
const allBannedLinkTexts = bannedLinkText.concat(
let bannedLinkTexts = bannedLinkText.concat(
params.config.additional_banned_texts || []
);
const exceptions = params.config.exceptions || [];
if (exceptions.length > 0) {
bannedLinkTexts = bannedLinkTexts.filter(
(text) => !exceptions.includes(text)
);
}
const inlineTokens = params.tokens.filter((t) => t.type === "inline");
for (const token of inlineTokens) {
const { children } = token;
Expand All @@ -35,7 +41,7 @@ module.exports = {
linkText = "";
} else if (type === "link_close") {
inLink = false;
if (allBannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
if (bannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
onError({
lineNumber: child.lineNumber,
detail: `For link: ${linkText}`,
Expand Down
12 changes: 12 additions & 0 deletions test/no-generic-link-text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,17 @@ describe("GH002: No Generic Link Text", () => {

expect(failedRules).toHaveLength(1);
});

test("exceptions can be configured", async () => {
const results = await runTest(
["[Link](primer.style/components/Link)"],
noGenericLinkTextRule,
{ exceptions: ["link"] }
);

for (const result of results) {
expect(result).not.toBeDefined();
}
});
});
});

0 comments on commit 207b296

Please sign in to comment.