Skip to content

Commit

Permalink
Fix no-ref-as-operand and allow lint when ref as right operator
Browse files Browse the repository at this point in the history
  • Loading branch information
lakb248 committed Aug 11, 2023
1 parent f607af7 commit 0c52fd7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 0 additions & 3 deletions lib/rules/no-ref-as-operand.js
Expand Up @@ -104,9 +104,6 @@ module.exports = {
// refValue || other, refValue && other. ignore: other || refValue
/** @param {Identifier & {parent: LogicalExpression}} node */
'LogicalExpression>Identifier'(node) {
if (node.parent.left !== node) {
return
}
// Report only constants.
const data = refReferences.get(node)
if (
Expand Down
16 changes: 14 additions & 2 deletions tests/lib/rules/no-ref-as-operand.js
Expand Up @@ -68,6 +68,8 @@ tester.run('no-ref-as-operand', rule, {
1 - count.value
count.value || other
count.value && other
other && count.value
other || count.value
var foo = count.value ? x : y
`,
`
Expand All @@ -78,8 +80,6 @@ tester.run('no-ref-as-operand', rule, {
`
import { ref } from 'vue'
const foo = ref(true)
var a = other || foo // ignore
var b = other && foo // ignore
let bar = ref(true)
var a = bar || other
Expand Down Expand Up @@ -451,12 +451,16 @@ tester.run('no-ref-as-operand', rule, {
const foo = ref(true)
var a = foo || other
var b = foo && other
var c = other || foo
var d = other && foo
`,
output: `
import { ref } from 'vue'
const foo = ref(true)
var a = foo.value || other
var b = foo.value && other
var c = other || foo.value
var d = other && foo.value
`,
errors: [
{
Expand All @@ -466,6 +470,14 @@ tester.run('no-ref-as-operand', rule, {
{
messageId: 'requireDotValue',
line: 5
},
{
messageId: 'requireDotValue',
line: 6
},
{
messageId: 'requireDotValue',
line: 7
}
]
},
Expand Down

0 comments on commit 0c52fd7

Please sign in to comment.