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

Conversation

lakb248
Copy link

@lakb248 lakb248 commented Aug 11, 2023

fix #2271

@ota-meshi
Copy link
Member

Thanks for this PR.
However, I think that this PR change has caused false positives in the following usages.

<script setup lang="ts">
import { ref, Ref } from 'vue'
const refValue1: Ref<number>  = ref(0)
const maybeRefValue: Ref<number> | null = getMaybeRef()
const refValue2 = maybeRefValue || refValue1
console.log(refValue2.value)
</script>

I think we should keep track of how the result of the expression is used.
Also, I think the ternary operator could be improved if it would be possible to track the usage of the result of the expression.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ota-meshi ota-meshi marked this pull request as draft January 30, 2024 14:23
@grindpride
Copy link

@ota-meshi @lakb248
Maybe put the logic for this rule in a separate no-ref-as-operand-strict rule, or customize with a parameter (strictCheck) of the current one?
In my code there are no cases of the following type

const refValue1: Ref<number>  = ref(0)
const maybeRefValue: Ref<number> | null = getMaybeRef()
const refValue2 = maybeRefValue || refValue1

But errors with such case use are often encountered

const refValue1: Ref<number>  = ref(0)
if (refValue1) {
  //incorrect condition
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

vue/no-ref-as-operand only lint left identifier of a logical expression
3 participants