Skip to content

Commit 55646bd

Browse files
authored
Fixed false positives for watch with properties in vue/no-unused-properties rule. (#1169)
1 parent f35154b commit 55646bd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/rules/no-unused-properties.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ module.exports = {
433433
node,
434434
new Set([GROUP_WATCHER])
435435
)) {
436-
watcherNames.add(watcher.name)
436+
let path
437+
for (const seg of watcher.name.split('.')) {
438+
path = path ? `${path}.${seg}` : seg
439+
watcherNames.add(path)
440+
}
437441
}
438442
for (const prop of utils.iterateProperties(node, groups)) {
439443
if (watcherNames.has(prop.name)) {

tests/lib/rules/no-unused-properties.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,21 @@ tester.run('no-unused-properties', rule, {
248248
`,
249249
options: allOptions
250250
},
251+
{
252+
filename: 'test.vue',
253+
code: `
254+
<script>
255+
export default {
256+
props: ['foo'],
257+
watch: {
258+
'foo.bar'() {
259+
alert('Increased!');
260+
},
261+
},
262+
};
263+
</script>
264+
`
265+
},
251266

252267
// data used as a template identifier
253268
{

0 commit comments

Comments
 (0)