Skip to content

Commit 207b296

Browse files
authored
Allow exceptions to be configured (#27)
1 parent 5763159 commit 207b296

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

no-generic-link-text.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ module.exports = {
1919
tags: ["accessibility", "links"],
2020
function: function GH002(params, onError) {
2121
// markdown syntax
22-
const allBannedLinkTexts = bannedLinkText.concat(
22+
let bannedLinkTexts = bannedLinkText.concat(
2323
params.config.additional_banned_texts || []
2424
);
25+
const exceptions = params.config.exceptions || [];
26+
if (exceptions.length > 0) {
27+
bannedLinkTexts = bannedLinkTexts.filter(
28+
(text) => !exceptions.includes(text)
29+
);
30+
}
2531
const inlineTokens = params.tokens.filter((t) => t.type === "inline");
2632
for (const token of inlineTokens) {
2733
const { children } = token;
@@ -35,7 +41,7 @@ module.exports = {
3541
linkText = "";
3642
} else if (type === "link_close") {
3743
inLink = false;
38-
if (allBannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
44+
if (bannedLinkTexts.includes(stripAndDowncaseText(linkText))) {
3945
onError({
4046
lineNumber: child.lineNumber,
4147
detail: `For link: ${linkText}`,

test/no-generic-link-text.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,17 @@ describe("GH002: No Generic Link Text", () => {
7575

7676
expect(failedRules).toHaveLength(1);
7777
});
78+
79+
test("exceptions can be configured", async () => {
80+
const results = await runTest(
81+
["[Link](primer.style/components/Link)"],
82+
noGenericLinkTextRule,
83+
{ exceptions: ["link"] }
84+
);
85+
86+
for (const result of results) {
87+
expect(result).not.toBeDefined();
88+
}
89+
});
7890
});
7991
});

0 commit comments

Comments
 (0)