forked from vuejs/eslint-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-template-target-blank.js
68 lines (62 loc) · 2.98 KB
/
no-template-target-blank.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @fileoverview disallow target="_blank" attribute without rel="noopener noreferrer"
* @author Sosukesuzuki
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const rule = require('../../../lib/rules/no-template-target-blank')
const RuleTester = require('eslint').RuleTester
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: { ecmaVersion: 2015 }
})
ruleTester.run('no-template-target-blank', rule, {
valid: [
{ code: '<template><a>link</a></template>' },
{ code: '<template><a attr>link</a></template>' },
{ code: '<template><a target>link</a></template>' },
{ code: '<template><a href="https://eslint.vuejs.org">link</a></template>' },
{ code: '<template><a :href="link">link</a></template>' },
{ code: '<template><a :href="link" target="_blank" rel="noopener noreferrer">link</a></template>' },
{ code: '<template><a href="https://eslint.vuejs.org" target="_blank" rel="noopener noreferrer">link</a></template>' },
{
code: '<template><a href="https://eslint.vuejs.org" target="_blank" rel="noopener">link</a></template>',
options: [{ allowReferrer: true }]
},
{ code: '<template><a href="/foo" target="_blank">link</a></template>' },
{ code: '<template><a href="/foo" target="_blank" rel="noopener noreferrer">link</a></template>' },
{ code: '<template><a href="foo/bar" target="_blank">link</a></template>' },
{ code: '<template><a href="foo/bar" target="_blank" rel="noopener noreferrer">link</a></template>' },
{
code: '<template><a :href="link" target="_blank">link</a></template>',
options: [{ enforceDynamicLinks: 'never' }]
}
],
invalid: [
{
code: '<template><a href="https://eslint.vuejs.org" target="_blank">link</a></template>',
errors: ['Using target="_blank" without rel="noopener noreferrer" is a security risk.']
},
{
code: '<template><a href="https://eslint.vuejs.org" target="_blank" rel="noopenernoreferrer">link</a></template>',
errors: ['Using target="_blank" without rel="noopener noreferrer" is a security risk.']
},
{
code: '<template><a :href="link" target="_blank" rel=3>link</a></template>',
errors: ['Using target="_blank" without rel="noopener noreferrer" is a security risk.']
},
{
code: '<template><a :href="link" target="_blank">link</a></template>',
errors: ['Using target="_blank" without rel="noopener noreferrer" is a security risk.']
},
{
code: '<template><a href="https://eslint.vuejs.org" target="_blank" rel="noopener">link</a></template>',
errors: ['Using target="_blank" without rel="noopener noreferrer" is a security risk.']
}
]
})