File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,11 @@ You should also specify settings that will be shared across all the plugin rules
4848 " forbidExtraProps" ,
4949 {" property" : " freeze" , " object" : " Object" },
5050 {" property" : " myFavoriteWrapper" }
51+ ],
52+ " linkComponents" : [
53+ // Components used as alternatives to <a> for linking, eg. <Link to={ url } />
54+ " Hyperlink" ,
55+ {" name" : " Link" , " linkAttribute" : " to" }
5156 ]
5257 }
5358}
Original file line number Diff line number Diff line change 1+ /**
2+ * @fileoverview Utility functions for propWrapperFunctions setting
3+ */
4+ 'use strict' ;
5+
6+ const DEFAULT_LINK_COMPONENTS = [ 'a' ] ;
7+ const DEFAULT_LINK_ATTRIBUTE = 'href' ;
8+
9+ function getLinkComponents ( context ) {
10+ const settings = context . settings || { } ;
11+ return new Map ( DEFAULT_LINK_COMPONENTS . concat ( settings . linkComponents || [ ] ) . map ( value => {
12+ if ( typeof value === 'string' ) {
13+ return [ value , DEFAULT_LINK_ATTRIBUTE ] ;
14+ }
15+ return [ value . name , value . linkAttribute ] ;
16+ } ) ) ;
17+ }
18+
19+ module . exports = {
20+ getLinkComponents : getLinkComponents
21+ } ;
Original file line number Diff line number Diff line change 1+ /* eslint-env mocha */
2+ 'use strict' ;
3+
4+ const assert = require ( 'assert' ) ;
5+ const linkComponentsUtil = require ( '../../lib/util/linkComponents' ) ;
6+
7+ describe ( 'linkComponentsFunctions' , ( ) => {
8+ describe ( 'getLinkComponents' , ( ) => {
9+ it ( 'returns a default map of components' , ( ) => {
10+ const context = { } ;
11+ assert . deepStrictEqual ( linkComponentsUtil . getLinkComponents ( context ) , new Map ( [
12+ [ 'a' , 'href' ]
13+ ] ) ) ;
14+ } ) ;
15+
16+ it ( 'returns a map of components' , ( ) => {
17+ const linkComponents = [
18+ 'Hyperlink' ,
19+ {
20+ name : 'Link' ,
21+ linkAttribute : 'to'
22+ }
23+ ] ;
24+ const context = {
25+ settings : {
26+ linkComponents : linkComponents
27+ }
28+ } ;
29+ assert . deepStrictEqual ( linkComponentsUtil . getLinkComponents ( context ) , new Map ( [
30+ [ 'a' , 'href' ] ,
31+ [ 'Hyperlink' , 'href' ] ,
32+ [ 'Link' , 'to' ]
33+ ] ) ) ;
34+ } ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments