diff --git a/lib/rules/no-ref-as-operand.js b/lib/rules/no-ref-as-operand.js
index bfb344d24..fb5dc0881 100644
--- a/lib/rules/no-ref-as-operand.js
+++ b/lib/rules/no-ref-as-operand.js
@@ -52,26 +52,24 @@ module.exports = {
return {
Program() {
const tracker = new ReferenceTracker(context.getScope())
- const traceMap = {
- vue: {
- [ReferenceTracker.ESM]: true,
- ref: {
- [ReferenceTracker.CALL]: true
- },
- computed: {
- [ReferenceTracker.CALL]: true
- },
- toRef: {
- [ReferenceTracker.CALL]: true
- },
- customRef: {
- [ReferenceTracker.CALL]: true
- },
- shallowRef: {
- [ReferenceTracker.CALL]: true
- }
+ const traceMap = utils.createCompositionApiTraceMap({
+ [ReferenceTracker.ESM]: true,
+ ref: {
+ [ReferenceTracker.CALL]: true
+ },
+ computed: {
+ [ReferenceTracker.CALL]: true
+ },
+ toRef: {
+ [ReferenceTracker.CALL]: true
+ },
+ customRef: {
+ [ReferenceTracker.CALL]: true
+ },
+ shallowRef: {
+ [ReferenceTracker.CALL]: true
}
- }
+ })
for (const { node, path } of tracker.iterateEsmReferences(traceMap)) {
const variableDeclarator = node.parent
diff --git a/lib/utils/index.js b/lib/utils/index.js
index 7fae65530..085c596ad 100644
--- a/lib/utils/index.js
+++ b/lib/utils/index.js
@@ -1532,6 +1532,15 @@ module.exports = {
}
},
+ /**
+ * Wraps composition API trace map in both 'vue' and '@vue/composition-api' imports
+ * @param {import('eslint-utils').TYPES.TraceMap} map
+ */
+ createCompositionApiTraceMap: (map) => ({
+ vue: map,
+ '@vue/composition-api': map
+ }),
+
/**
* Checks whether or not the tokens of two given nodes are same.
* @param {ASTNode} left A node 1 to compare.
diff --git a/tests/lib/rules/no-ref-as-operand.js b/tests/lib/rules/no-ref-as-operand.js
index 5d53a5571..ca553e35c 100644
--- a/tests/lib/rules/no-ref-as-operand.js
+++ b/tests/lib/rules/no-ref-as-operand.js
@@ -39,6 +39,23 @@ tester.run('no-ref-as-operand', rule, {
`,
`
+
+ `,
+ `
import { ref } from 'vue'
const count = ref(0)
if (count.value) {}
@@ -202,6 +219,48 @@ tester.run('no-ref-as-operand', rule, {
}
]
},
+ {
+ code: `
+
+ `,
+ errors: [
+ {
+ messageId: 'requireDotValue',
+ line: 8,
+ column: 13,
+ endLine: 8,
+ endColumn: 18
+ },
+ {
+ messageId: 'requireDotValue',
+ line: 9,
+ column: 25,
+ endLine: 9,
+ endColumn: 30
+ },
+ {
+ messageId: 'requireDotValue',
+ line: 10,
+ column: 29,
+ endLine: 10,
+ endColumn: 34
+ }
+ ]
+ },
{
code: `
import { ref } from 'vue'