Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 207b296

Browse filesBrowse files
authored
Allow exceptions to be configured (#27)
1 parent 5763159 commit 207b296
Copy full SHA for 207b296

File tree

Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed

‎no-generic-link-text.js

Copy file name to clipboardExpand all lines: no-generic-link-text.js
+8-2Lines 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

Copy file name to clipboardExpand all lines: test/no-generic-link-text.test.js
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.