Skip to content

Commit 90bcd30

Browse files
committed
Fix tests and code style
1 parent 48b1250 commit 90bcd30

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
const includes = require('array-includes');
89
const docsUrl = require('../util/docsUrl');
910
const linkComponentsUtil = require('../util/linkComponents');
1011
const report = require('../util/report');
@@ -28,8 +29,8 @@ function shouldVerifyProp(node, config) {
2829

2930
if (!name || !parentName || !config.has(parentName)) return false;
3031

31-
const attributes = config.get(parentName)
32-
return attributes.includes(name);
32+
const attributes = config.get(parentName);
33+
return includes(attributes, name);
3334
}
3435

3536
function parseLegacyOption(config, option) {

lib/rules/jsx-no-target-blank.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
const includes = require('array-includes');
89
const docsUrl = require('../util/docsUrl');
910
const linkComponentsUtil = require('../util/linkComponents');
1011
const report = require('../util/report');
@@ -49,15 +50,15 @@ function attributeValuePossiblyBlank(attribute) {
4950
}
5051

5152
function hasExternalLink(node, linkAttributes, warnOnSpreadAttributes, spreadAttributeIndex) {
52-
const linkIndex = findLastIndex(node.attributes, (attr) => attr.name && linkAttributes.includes(attr.name.name));
53+
const linkIndex = findLastIndex(node.attributes, (attr) => attr.name && includes(linkAttributes, attr.name.name));
5354
const foundExternalLink = linkIndex !== -1 && ((attr) => attr.value && attr.value.type === 'Literal' && /^(?:\w+:|\/\/)/.test(attr.value.value))(
5455
node.attributes[linkIndex]);
5556
return foundExternalLink || (warnOnSpreadAttributes && linkIndex < spreadAttributeIndex);
5657
}
5758

5859
function hasDynamicLink(node, linkAttributes) {
5960
const dynamicLinkIndex = findLastIndex(node.attributes, (attr) => attr.name
60-
&& linkAttributes.includes(attr.name.name)
61+
&& includes(linkAttributes, attr.name.name)
6162
&& attr.value
6263
&& attr.value.type === 'JSXExpressionContainer');
6364
if (dynamicLinkIndex !== -1) {

lib/util/linkComponents.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function getFormComponents(context) {
2626
if (typeof value === 'string') {
2727
return [value, [DEFAULT_FORM_ATTRIBUTE]];
2828
}
29-
return [value.name, value.formAttributes || [value.formAttribute]];
29+
return [value.name, [].concat(value.formAttribute)];
3030
}));
3131
}
3232

@@ -39,7 +39,7 @@ function getLinkComponents(context) {
3939
if (typeof value === 'string') {
4040
return [value, [DEFAULT_LINK_ATTRIBUTE]];
4141
}
42-
return [value.name, value.linkAttributes || [value.linkAttribute]];
42+
return [value.name, [].concat(value.linkAttribute)];
4343
}));
4444
}
4545

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ ruleTester.run('jsx-no-script-url', rule, {
7171
errors: [{ messageId: 'noScriptURL' }],
7272
settings: {
7373
linkComponents: [
74-
{ name: 'Foo', linkAttribute: ['to'] }
75-
]
74+
{ name: 'Foo', linkAttribute: 'to' },
75+
],
7676
},
7777
},
7878
{
7979
code: '<Foo href="javascript:"></Foo>',
8080
errors: [{ messageId: 'noScriptURL' }],
8181
settings: {
8282
linkComponents: [
83-
{ name: 'Foo', linkAttribute: ['to'] }
84-
]
83+
{ name: 'Foo', linkAttribute: ['to', 'href'] },
84+
],
8585
},
8686
},
8787
{
@@ -120,8 +120,8 @@ ruleTester.run('jsx-no-script-url', rule, {
120120
],
121121
settings: {
122122
linkComponents: [
123-
{ name: 'Foo', linkAttribute: ['to', 'href'] }
124-
]
123+
{ name: 'Foo', linkAttribute: ['to', 'href'] },
124+
],
125125
},
126126
},
127127
]),

tests/lib/rules/jsx-no-target-blank.js

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ ruleTester.run('jsx-no-target-blank', rule, {
102102
options: [{ enforceDynamicLinks: 'never' }],
103103
settings: { linkComponents: { name: 'Link', linkAttribute: 'to' } },
104104
},
105+
{
106+
code: '<Link target="_blank" to={ dynamicLink }></Link>',
107+
options: [{ enforceDynamicLinks: 'never' }],
108+
settings: { linkComponents: { name: 'Link', linkAttribute: ['to'] } },
109+
},
105110
{
106111
code: '<a href="foobar" target="_blank" rel="noopener"></a>',
107112
options: [{ allowReferrer: true }],

0 commit comments

Comments
 (0)