Skip to content

Commit 211d1a5

Browse files
committed
Fix code as per PR comments
1 parent 0659798 commit 211d1a5

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

docs/rules/jsx-no-script-url.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Examples of **correct** code for this rule:
2323
<a href={"javascript:"}></a>
2424
```
2525

26-
This rule takes into account `linkComponents` setting.
26+
This rule takes the `linkComponents` setting into account.
2727

2828
## Rule Options
2929

@@ -48,9 +48,8 @@ This rule takes into account `linkComponents` setting.
4848
Allows you to indicate a specific list of properties used by a custom component to be checked.
4949
This will override anything passed to `linkComponents` setting.
5050

51-
NOTE: This rule now takes into account `linkComponents` setting and it should be used as primary source of link components.
52-
The rule still allows passing link components as rule option, but it is meant only as backwards-compatibility feature.
53-
New setups should only use `linkComponents` setting.
51+
NOTE: This rule now takes into account the `linkComponents` setting, which should be used as the sole source of truth for link components.
52+
The rule still allows passing link components as rule option for backwards compatibility, but this option is deprecated.
5453

5554
### name
5655

lib/rules/jsx-no-script-url.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ function shouldVerifyProp(node, config) {
3131
return name === config.get(parentName)
3232
}
3333

34-
function parseLegacyOption(option) {
35-
const config = linkComponentsUtil.getLinkComponents({}) // get defaults
36-
option.forEach(function(opt) {
37-
opt.props.forEach(function(prop) { // FIXME: only last prop will work at the moment
38-
config.set(opt.name, prop)
39-
})
34+
function parseLegacyOption(config, option) {
35+
option.forEach((opt) => {
36+
opt.props.forEach((prop) => {
37+
config.set(opt.name, prop);
38+
});
4039
})
41-
return config
4240
}
4341

4442
const messages = {
@@ -75,13 +73,16 @@ module.exports = {
7573
},
7674
required: ['name', 'props'],
7775
additionalProperties: false,
78-
deprecated: true, // ?
76+
deprecated: true,
7977
},
8078
}],
8179
},
8280

8381
create(context) {
84-
const linkComponents = context.options[0] ? parseLegacyOption(context.options[0]) : linkComponentsUtil.getLinkComponents(context);
82+
const linkComponents = linkComponentsUtil.getLinkComponents(context);
83+
if (context.options[0]) {
84+
parseLegacyOption(linkComponents, context.options[0]);
85+
}
8586

8687
return {
8788
JSXAttribute(node) {

0 commit comments

Comments
 (0)