File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Original file line number Diff line number Diff line change @@ -19,9 +19,15 @@ module.exports = {
19
19
tags : [ "accessibility" , "links" ] ,
20
20
function : function GH002 ( params , onError ) {
21
21
// markdown syntax
22
- const allBannedLinkTexts = bannedLinkText . concat (
22
+ let bannedLinkTexts = bannedLinkText . concat (
23
23
params . config . additional_banned_texts || [ ]
24
24
) ;
25
+ const exceptions = params . config . exceptions || [ ] ;
26
+ if ( exceptions . length > 0 ) {
27
+ bannedLinkTexts = bannedLinkTexts . filter (
28
+ ( text ) => ! exceptions . includes ( text )
29
+ ) ;
30
+ }
25
31
const inlineTokens = params . tokens . filter ( ( t ) => t . type === "inline" ) ;
26
32
for ( const token of inlineTokens ) {
27
33
const { children } = token ;
@@ -35,7 +41,7 @@ module.exports = {
35
41
linkText = "" ;
36
42
} else if ( type === "link_close" ) {
37
43
inLink = false ;
38
- if ( allBannedLinkTexts . includes ( stripAndDowncaseText ( linkText ) ) ) {
44
+ if ( bannedLinkTexts . includes ( stripAndDowncaseText ( linkText ) ) ) {
39
45
onError ( {
40
46
lineNumber : child . lineNumber ,
41
47
detail : `For link: ${ linkText } ` ,
Original file line number Diff line number Diff line change @@ -75,5 +75,17 @@ describe("GH002: No Generic Link Text", () => {
75
75
76
76
expect ( failedRules ) . toHaveLength ( 1 ) ;
77
77
} ) ;
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
+ } ) ;
78
90
} ) ;
79
91
} ) ;
You can’t perform that action at this time.
0 commit comments