|
| 1 | +/** |
| 2 | + * @author 薛定谔的猫<[email protected]> |
| 3 | + * @copyright 2017 薛定谔的猫. All rights reserved. |
| 4 | + * See LICENSE file in root directory for full license. |
| 5 | + */ |
| 6 | +'use strict' |
| 7 | + |
| 8 | +// ------------------------------------------------------------------------------ |
| 9 | +// Requirements |
| 10 | +// ------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +const RuleTester = require('eslint').RuleTester |
| 13 | +const rule = require('../../../lib/rules/no-unused-vars') |
| 14 | + |
| 15 | +// ------------------------------------------------------------------------------ |
| 16 | +// Tests |
| 17 | +// ------------------------------------------------------------------------------ |
| 18 | + |
| 19 | +const tester = new RuleTester({ |
| 20 | + parser: 'vue-eslint-parser', |
| 21 | + parserOptions: { ecmaVersion: 2015 } |
| 22 | +}) |
| 23 | + |
| 24 | +tester.run('no-unused-vars', rule, { |
| 25 | + valid: [ |
| 26 | + { |
| 27 | + code: '<template><ol v-for="i in 5"><li>{{i}}</li></ol></template>' |
| 28 | + }, |
| 29 | + { |
| 30 | + code: '<template><ol v-for="i in 5"><li :prop="i"></li></ol></template>' |
| 31 | + }, |
| 32 | + { |
| 33 | + code: '<template v-for="i in 5"><comp v-for="j in 10">{{i}}{{j}}</comp></template>' |
| 34 | + }, |
| 35 | + { |
| 36 | + code: '<template><ol v-for="i in data"><li v-for="f in i">{{ f.bar.baz }}</li></ol></template>' |
| 37 | + }, |
| 38 | + { |
| 39 | + code: '<template scope="props">{{props}}</template>' |
| 40 | + }, |
| 41 | + { |
| 42 | + code: '<template scope="props"><span v-if="props"></span></template>' |
| 43 | + } |
| 44 | + ], |
| 45 | + invalid: [ |
| 46 | + { |
| 47 | + code: '<template><ol v-for="i in 5"><li></li></ol></template>', |
| 48 | + errors: ['\'i\' is defined but never used.'] |
| 49 | + }, |
| 50 | + { |
| 51 | + code: '<template scope="props"></template>', |
| 52 | + errors: ['\'props\' is defined but never used.'] |
| 53 | + }, |
| 54 | + { |
| 55 | + code: '<template v-for="i in 5"><comp v-for="j in 10">{{i}}{{i}}</comp></template>', |
| 56 | + errors: ['\'j\' is defined but never used.'] |
| 57 | + }, |
| 58 | + { |
| 59 | + code: '<template><ol v-for="i in data"><li v-for="f in i"></li></ol></template>', |
| 60 | + errors: ['\'f\' is defined but never used.'] |
| 61 | + }, |
| 62 | + { |
| 63 | + code: '<template><div v-for="(v, i, c) in foo"></div></template>', |
| 64 | + errors: ['\'v\' is defined but never used.', '\'i\' is defined but never used.', '\'c\' is defined but never used.'] |
| 65 | + } |
| 66 | + ] |
| 67 | +}) |
0 commit comments