Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c981ea

Browse files
Adam Haglundota-meshi
Adam Haglund
andauthored
Check @vue/composition-api Usages in no-ref-as-operand (#1225)
* check '@vue/composition-api' usages in no-ref-as-operand * add test cases * add composition-api checking to no-lifecycle-after-await * add composition-api checking to no-watch-after-await * prettier fix * revert adding vue 2 support for async rules Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
1 parent fec4e41 commit 8c981ea

File tree

3 files changed

+85
-19
lines changed

3 files changed

+85
-19
lines changed

‎lib/rules/no-ref-as-operand.js‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,24 @@ module.exports = {
5252
return {
5353
Program() {
5454
const tracker = new ReferenceTracker(context.getScope())
55-
const traceMap = {
56-
vue: {
57-
[ReferenceTracker.ESM]: true,
58-
ref: {
59-
[ReferenceTracker.CALL]: true
60-
},
61-
computed: {
62-
[ReferenceTracker.CALL]: true
63-
},
64-
toRef: {
65-
[ReferenceTracker.CALL]: true
66-
},
67-
customRef: {
68-
[ReferenceTracker.CALL]: true
69-
},
70-
shallowRef: {
71-
[ReferenceTracker.CALL]: true
72-
}
55+
const traceMap = utils.createCompositionApiTraceMap({
56+
[ReferenceTracker.ESM]: true,
57+
ref: {
58+
[ReferenceTracker.CALL]: true
59+
},
60+
computed: {
61+
[ReferenceTracker.CALL]: true
62+
},
63+
toRef: {
64+
[ReferenceTracker.CALL]: true
65+
},
66+
customRef: {
67+
[ReferenceTracker.CALL]: true
68+
},
69+
shallowRef: {
70+
[ReferenceTracker.CALL]: true
7371
}
74-
}
72+
})
7573

7674
for (const { node, path } of tracker.iterateEsmReferences(traceMap)) {
7775
const variableDeclarator = node.parent

‎lib/utils/index.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,15 @@ module.exports = {
15321532
}
15331533
},
15341534

1535+
/**
1536+
* Wraps composition API trace map in both 'vue' and '@vue/composition-api' imports
1537+
* @param {import('eslint-utils').TYPES.TraceMap} map
1538+
*/
1539+
createCompositionApiTraceMap: (map) => ({
1540+
vue: map,
1541+
'@vue/composition-api': map
1542+
}),
1543+
15351544
/**
15361545
* Checks whether or not the tokens of two given nodes are same.
15371546
* @param {ASTNode} left A node 1 to compare.

‎tests/lib/rules/no-ref-as-operand.js‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ tester.run('no-ref-as-operand', rule, {
3939
</script>
4040
`,
4141
`
42+
<script>
43+
import { ref } from '@vue/composition-api'
44+
export default {
45+
setup() {
46+
const count = ref(0)
47+
console.log(count.value) // 0
48+
49+
count.value++
50+
console.log(count.value) // 1
51+
return {
52+
count
53+
}
54+
}
55+
}
56+
</script>
57+
`,
58+
`
4259
import { ref } from 'vue'
4360
const count = ref(0)
4461
if (count.value) {}
@@ -202,6 +219,48 @@ tester.run('no-ref-as-operand', rule, {
202219
}
203220
]
204221
},
222+
{
223+
code: `
224+
<script>
225+
import { ref } from '@vue/composition-api'
226+
export default {
227+
setup() {
228+
let count = ref(0)
229+
230+
count++ // error
231+
console.log(count + 1) // error
232+
console.log(1 + count) // error
233+
return {
234+
count
235+
}
236+
}
237+
}
238+
</script>
239+
`,
240+
errors: [
241+
{
242+
messageId: 'requireDotValue',
243+
line: 8,
244+
column: 13,
245+
endLine: 8,
246+
endColumn: 18
247+
},
248+
{
249+
messageId: 'requireDotValue',
250+
line: 9,
251+
column: 25,
252+
endLine: 9,
253+
endColumn: 30
254+
},
255+
{
256+
messageId: 'requireDotValue',
257+
line: 10,
258+
column: 29,
259+
endLine: 10,
260+
endColumn: 34
261+
}
262+
]
263+
},
205264
{
206265
code: `
207266
import { ref } from 'vue'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /