-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathno-unused-vars.js
92 lines (87 loc) · 2.98 KB
/
no-unused-vars.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* @author 薛定谔的猫<[email protected]>
* @copyright 2017 薛定谔的猫. All rights reserved.
* See LICENSE file in root directory for full license.
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/no-unused-vars')
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const tester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2015 }
})
tester.run('no-unused-vars', rule, {
valid: [
{
code: '<template><ol v-for="i in 5"><li>{{i}}</li></ol></template>'
},
{
code: '<template><ol v-for="i in 5"><li :prop="i"></li></ol></template>'
},
{
code: '<template v-for="i in 5"><comp v-for="j in 10">{{i}}{{j}}</comp></template>'
},
{
code: '<template><ol v-for="i in data"><li v-for="f in i">{{ f.bar.baz }}</li></ol></template>'
},
{
code: '<template scope="props">{{props}}</template>'
},
{
code: '<template scope="props"><span v-if="props"></span></template>'
},
{
code: '<template><div v-for="(item, key) in items" :key="key">{{item.name}}</div></template>'
},
{
code: '<template><div v-for="(v, i, c) in foo">{{c}}</div></template>'
},
{
code: '<template><div v-for="x in foo">{{value | f(x)}}</div></template>'
}
],
invalid: [
{
code: '<template><ol v-for="i in 5"><li></li></ol></template>',
errors: ["'i' is defined but never used."]
},
{
code: '<template scope="props"></template>',
errors: ["'props' is defined but never used."]
},
{
code: '<template v-for="i in 5"><comp v-for="j in 10">{{i}}{{i}}</comp></template>',
errors: ["'j' is defined but never used."]
},
{
code: '<template><ol v-for="i in data"><li v-for="f in i"></li></ol></template>',
errors: ["'f' is defined but never used."]
},
{
code: '<template><div v-for="(a, b, c) in foo"></div></template>',
errors: ["'a' is defined but never used.", "'b' is defined but never used.", "'c' is defined but never used."]
},
{
code: '<template><div v-for="(a, b, c) in foo">{{a}}</div></template>',
errors: ["'b' is defined but never used.", "'c' is defined but never used."]
},
{
code: '<template><div v-for="(a, b, c) in foo">{{b}}</div></template>',
errors: ["'c' is defined but never used."]
},
{
code: '<template><div v-for="(item, key) in items" :key="item.id">{{item.name}}</div></template>',
errors: ["'key' is defined but never used."]
},
{
code: '<template><div v-for="x in items">{{value | x}}</div></template>',
errors: ["'x' is defined but never used."]
}
]
})