Skip to content

Commit 467ef96

Browse files
authored
Fix false negatives for member access with $ in vue/this-in-template rule (#1446)
1 parent 7099954 commit 467ef96

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rules/this-in-template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = {
8383
!propertyName ||
8484
scopeStack.nodes.some((el) => el.name === propertyName) ||
8585
RESERVED_NAMES.has(propertyName) || // this.class | this['class']
86-
/^[0-9].*$|[^a-zA-Z0-9_]/.test(propertyName) // this['0aaaa'] | this['foo-bar bas']
86+
/^[0-9].*$|[^a-zA-Z0-9_$]/.test(propertyName) // this['0aaaa'] | this['foo-bar bas']
8787
) {
8888
return
8989
}

tests/lib/rules/this-in-template.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,16 @@ ruleTester.run('this-in-template', rule, {
222222
.concat(
223223
createInvalidTests('', ['always'], "Expected 'this'.", 'Identifier')
224224
)
225+
.concat([
226+
{
227+
code: `<template><div v-if="fn(this.$foo)"></div></template><!-- never -->`,
228+
errors: ["Unexpected usage of 'this'."],
229+
options: ['never']
230+
},
231+
{
232+
code: `<template><div :class="{ foo: this.$foo }"></div></template><!-- never -->`,
233+
errors: ["Unexpected usage of 'this'."],
234+
options: ['never']
235+
}
236+
])
225237
})

0 commit comments

Comments
 (0)