Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-ref-as-operand and allow lint when ref as right operator #2273

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions lib/rules/no-ref-as-operand.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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