forked from vuejs/eslint-plugin-vue
/
no-unused-vars.js
135 lines (128 loc) · 4.46 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* @author 薛定谔的猫<hh_2013@foxmail.com>
* @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: require.resolve('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><template scope="props">{{props}}</template></template>'
},
{
code: '<template><template scope="props"><span v-if="props"></span></template></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>'
},
{
code: '<template><div v-for="x in foo" :[x]></div></template>'
},
{
code: '<template><div v-for="_ in foo" ></div></template>',
options: [{ varIgnorePattern: '^_' }]
},
{
code: '<template><div v-for="_i in foo" ></div></template>'
},
{
code: '<template><div v-for="ignorei in foo" ></div></template>',
options: [{ varIgnorePattern: '^ignore' }]
},
{
code: '<template><div v-for="thisisignore in foo" ></div></template>',
options: [{ varIgnorePattern: 'ignore$' }]
}
],
invalid: [
{
code: '<template><ol v-for="i in 5"><li></li></ol></template>',
errors: ["'i' is defined but never used."]
},
{
code: '<template><template scope="props"></template></template>',
errors: ["'props' is defined but never used."]
},
{
code: '<template><span slot-scope="props"></span></template>',
errors: ["'props' is defined but never used."]
},
{
code: '<template><span><template scope="props"></template></span></template>',
errors: ["'props' is defined but never used."]
},
{
code: '<template><div v-for="i in 5"><comp v-for="j in 10">{{i}}{{i}}</comp></div></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."]
},
{
code: '<template><div v-for="x in items">{{value}}</div></template>',
options: [{ varIgnorePattern: 'ignore$' }],
errors: ["'x' is defined but never used."]
},
{
code: '<template><span slot-scope="props"></span></template>',
errors: ["'props' is defined but never used."],
options: [{ varIgnorePattern: '^ignore' }]
},
{
code: '<template><span><template scope="props"></template></span></template>',
errors: ["'props' is defined but never used."],
options: [{ varIgnorePattern: '^ignore' }]
}
]
})