Skip to content

Commit 9eb6922

Browse files
committed
Change rule and docs
1 parent ca162fd commit 9eb6922

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Examples of **correct** code for this rule:
2323
<a href={"javascript:"}></a>
2424
```
2525

26+
This rule takes into account `linkComponents` setting.
27+
2628
## Rule Options
2729

2830
```json
@@ -44,6 +46,11 @@ Examples of **correct** code for this rule:
4446
```
4547

4648
Allows you to indicate a specific list of properties used by a custom component to be checked.
49+
This will override anything passed to `linkComponents` setting.
50+
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.
4754

4855
### name
4956

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
const docsUrl = require('../util/docsUrl');
9+
const linkComponentsUtil = require('../util/linkComponents');
910
const report = require('../util/report');
1011

1112
// ------------------------------------------------------------------------------
@@ -22,25 +23,25 @@ function hasJavaScriptProtocol(attr) {
2223
}
2324

2425
function shouldVerifyElement(node, config) {
25-
const name = node.name && node.name.name;
26-
return name === 'a' || config.find((i) => i.name === name);
26+
const name = node.name && node.name.name
27+
return name ? config.has(name) : false
2728
}
2829

2930
function shouldVerifyProp(node, config) {
3031
const name = node.name && node.name.name;
3132
const parentName = node.parent.name && node.parent.name.name;
3233

33-
if (parentName === 'a' && name === 'href') {
34-
return true;
35-
}
36-
37-
const el = config.find((i) => i.name === parentName);
38-
if (!el) {
39-
return false;
40-
}
34+
return (name && parentName) ? name === config.get(parentName) : false
35+
}
4136

42-
const props = el.props || [];
43-
return node.name && props.indexOf(name) !== -1;
37+
function parseLegacyOption(option) {
38+
const config = linkComponentsUtil.getLinkComponents({}) // get defaults
39+
option.forEach(function(opt) {
40+
opt.props.forEach(function(prop) { // FIXME: only last prop will work at the moment
41+
config.set(opt.name, prop)
42+
})
43+
})
44+
return config
4445
}
4546

4647
const messages = {
@@ -77,16 +78,18 @@ module.exports = {
7778
},
7879
required: ['name', 'props'],
7980
additionalProperties: false,
81+
deprecated: true, // ?
8082
},
8183
}],
8284
},
8385

8486
create(context) {
85-
const config = context.options[0] || [];
87+
const linkComponents = context.options[0] ? parseLegacyOption(context.options[0]) : linkComponentsUtil.getLinkComponents(context);
88+
8689
return {
8790
JSXAttribute(node) {
8891
const parent = node.parent;
89-
if (shouldVerifyElement(parent, config) && shouldVerifyProp(node, config) && hasJavaScriptProtocol(node)) {
92+
if (shouldVerifyElement(parent, linkComponents) && shouldVerifyProp(node, linkComponents) && hasJavaScriptProtocol(node)) {
9093
report(context, messages.noScriptURL, 'noScriptURL', {
9194
node,
9295
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy