Description
What rule do you want to change?
vue/no-unused-properties
Does this change cause the rule to produce more or fewer warnings?
More when strict: true
How will the change be implemented? (New option, new default behavior, etc.)?
I have argued that this should be the default behaviour, in line with externally-called methods being considered 'unused' unless explicitly labelled in JSDoc style. But, if this change is undesirable, a strict: true
option to vue/no-unused-properties might be a compromise, with the possibility of making strict: true
the default in future.
Please provide some example code that this change will affect:
<script>
export default {
data () {
return {
unusedData: 42
}
},
computed: {
notReferenced () {
return 'never seen'
},
},
mounted () {
const handlerName = 'eventHandler'
// Event registration code ommitted, but would end up calling via:
this[handlerName]
},
methods: {
eventHandler () {
// Used
},
notused () {
// should show as warning
}
}
}
</script>
What does the rule currently do for this code?
The presence of this[handlerName]
(as noted in the original ticket) makes it almost impossible for static analysis to determine whether any particular method or property is actually used. The current behaviour appears to assume that all properties, methods, data, and computeds are therefore used, and the above code produces no warnings at all. Commenting out this[handlerName]
restores the (in my opinion, correct) behaviour that only explicitly referenced properties are 'used'.
What will the rule do after it's changed?
Warn about any properties not explicitly referenced, or which are labelled as referenced by the developer using either // eslint-disable-next-line vue/no-unused-properties
or /** @public */
annotations.