forked from vuejs/eslint-plugin-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-this-in-template.js
79 lines (73 loc) · 2.21 KB
/
no-this-in-template.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
/**
* @fileoverview Disallow usage of `this` in template.
* @author Armano
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const rule = require('../../../lib/rules/no-this-in-template')
const RuleTester = require('eslint').RuleTester
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const ruleTester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2015 }
})
ruleTester.run('no-this-in-template', rule, {
valid: [
'',
'<template></template>',
'<template><div></div></template>',
'<template><div>{{ foo.bar }}</div></template>',
'<template><div v-for="foo in bar">{{ foo }}</div></template>',
'<template><div v-if="foo">{{ foo }}</div></template>',
'<template><div :class="foo">{{ foo }}</div></template>',
'<template><div :class="{this: foo}">{{ foo }}</div></template>'
],
invalid: [
{
code: '<template><div>{{ this.foo }}</div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
},
{
code: '<template><div :class="this.foo"></div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
},
{
code: '<template><div :class="{foo: this.foo}"></div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
},
{
code: '<template><div :class="{foo: this.foo()}"></div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
},
{
code: '<template><div v-if="this.foo"></div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
},
{
code: '<template><div v-for="foo in this.bar"></div></template>',
errors: [{
message: "Unexpected usage of 'this'.",
type: 'ThisExpression'
}]
}
]
})