From 207b296d98969ed888751f5c6006d5f729419ca7 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 27 Dec 2022 13:11:35 -0500 Subject: [PATCH] Allow exceptions to be configured (#27) --- no-generic-link-text.js | 10 ++++++++-- test/no-generic-link-text.test.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/no-generic-link-text.js b/no-generic-link-text.js index c16cd67..ac27ef2 100644 --- a/no-generic-link-text.js +++ b/no-generic-link-text.js @@ -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; @@ -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}`, diff --git a/test/no-generic-link-text.test.js b/test/no-generic-link-text.test.js index f51a1db..0a09475 100644 --- a/test/no-generic-link-text.test.js +++ b/test/no-generic-link-text.test.js @@ -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(); + } + }); }); });