Skip to content

Commit 8766e58

Browse files
authored
Add option to show warnings when props could be accessed via this
Ref vuejs#1636, this is my first stab at adding an option to not treat generic access to `this` as 'using' properties / data / computed, etc. If this is the right approach, I can try adding tests if needed. It's more general I think than what you'd proposed in that issue, but for my use case it works well.
1 parent a4226ea commit 8766e58

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/rules/no-unused-properties.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const GROUP_SETUP = 'setup'
5555
const GROUP_WATCHER = 'watch'
5656
const GROUP_EXPOSE = 'expose'
5757

58+
const STOPREPORTING_THIS = 'ThisExpression'
59+
5860
const PROPERTY_LABEL = {
5961
props: 'property',
6062
data: 'data',
@@ -206,7 +208,15 @@ module.exports = {
206208
uniqueItems: true
207209
},
208210
deepData: { type: 'boolean' },
209-
ignorePublicMembers: { type: 'boolean' }
211+
ignorePublicMembers: { type: 'boolean' },
212+
stopReporting: {
213+
type: 'array',
214+
items: {
215+
enum: [ STOPREPORTING_THIS ]
216+
},
217+
additionalItems: false,
218+
uniqueItems: true
219+
}
210220
},
211221
additionalProperties: false
212222
}
@@ -221,6 +231,7 @@ module.exports = {
221231
const groups = new Set(options.groups || [GROUP_PROPERTY])
222232
const deepData = Boolean(options.deepData)
223233
const ignorePublicMembers = Boolean(options.ignorePublicMembers)
234+
const stopReporting = new Set(options.stopReporting || [STOPREPORTING_THIS])
224235

225236
const propertyReferenceExtractor = definePropertyReferenceExtractor(context)
226237

@@ -560,6 +571,9 @@ module.exports = {
560571
if (!utils.isThis(node, context)) {
561572
return
562573
}
574+
if (!stopReporting.has(STOPREPORTING_THIS)) {
575+
return
576+
}
563577
const container = getVueComponentPropertiesContainer(vueData.node)
564578
const propertyReferences =
565579
propertyReferenceExtractor.extractFromExpression(node, false)

0 commit comments

Comments
 (0)