Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2116 from gbakernet/allow_custom_components_in_js…
…x_no_blank [New] add `linkComponents` setting [New] `jsx-no-target-blank`: add support for `linkComponents` setting
- Loading branch information
Showing
9 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* @fileoverview Utility functions for propWrapperFunctions setting | ||
*/ | ||
'use strict'; | ||
|
||
const DEFAULT_LINK_COMPONENTS = ['a']; | ||
const DEFAULT_LINK_ATTRIBUTE = 'href'; | ||
|
||
function getLinkComponents(context) { | ||
const settings = context.settings || {}; | ||
return new Map(DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || []).map(value => { | ||
if (typeof value === 'string') { | ||
return [value, DEFAULT_LINK_ATTRIBUTE]; | ||
} | ||
return [value.name, value.linkAttribute]; | ||
})); | ||
} | ||
|
||
module.exports = { | ||
getLinkComponents: getLinkComponents | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const linkComponentsUtil = require('../../lib/util/linkComponents'); | ||
|
||
describe('linkComponentsFunctions', () => { | ||
describe('getLinkComponents', () => { | ||
it('returns a default map of components', () => { | ||
const context = {}; | ||
assert.deepStrictEqual(linkComponentsUtil.getLinkComponents(context), new Map([ | ||
['a', 'href'] | ||
])); | ||
}); | ||
|
||
it('returns a map of components', () => { | ||
const linkComponents = [ | ||
'Hyperlink', | ||
{ | ||
name: 'Link', | ||
linkAttribute: 'to' | ||
} | ||
]; | ||
const context = { | ||
settings: { | ||
linkComponents: linkComponents | ||
} | ||
}; | ||
assert.deepStrictEqual(linkComponentsUtil.getLinkComponents(context), new Map([ | ||
['a', 'href'], | ||
['Hyperlink', 'href'], | ||
['Link', 'to'] | ||
])); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-env mocha */ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|