Skip to content

Commit

Permalink
Fix false negatives for member access with $ in `vue/this-in-templa…
Browse files Browse the repository at this point in the history
…te` rule (#1446)
  • Loading branch information
ota-meshi committed Mar 2, 2021
1 parent 7099954 commit 467ef96
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/this-in-template.js
Expand Up @@ -83,7 +83,7 @@ module.exports = {
!propertyName ||
scopeStack.nodes.some((el) => el.name === propertyName) ||
RESERVED_NAMES.has(propertyName) || // this.class | this['class']
/^[0-9].*$|[^a-zA-Z0-9_]/.test(propertyName) // this['0aaaa'] | this['foo-bar bas']
/^[0-9].*$|[^a-zA-Z0-9_$]/.test(propertyName) // this['0aaaa'] | this['foo-bar bas']
) {
return
}
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/this-in-template.js
Expand Up @@ -222,4 +222,16 @@ ruleTester.run('this-in-template', rule, {
.concat(
createInvalidTests('', ['always'], "Expected 'this'.", 'Identifier')
)
.concat([
{
code: `<template><div v-if="fn(this.$foo)"></div></template><!-- never -->`,
errors: ["Unexpected usage of 'this'."],
options: ['never']
},
{
code: `<template><div :class="{ foo: this.$foo }"></div></template><!-- never -->`,
errors: ["Unexpected usage of 'this'."],
options: ['never']
}
])
})

0 comments on commit 467ef96

Please sign in to comment.