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

MaybeRefs should be used with unref #2619

Open
jhoermann opened this issue Nov 21, 2024 · 1 comment
Open

MaybeRefs should be used with unref #2619

jhoermann opened this issue Nov 21, 2024 · 1 comment

Comments

@jhoermann
Copy link

Please describe what the rule should do:
Currently using a MaybeRef without using unref wouldn't lead to an eslint error:

const maybeRef: MaybeRef<boolean> = ref(false)
if (maybeRef) { // would be always true in this case but not catched with @typescript-eslint/no-unnecessary-condition
    ...
}

It should be enforced using unref in this case to prevent false positives in conditions.
Name of rule tbd.

What category should the rule belong to?
[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

@FloEdelmann
Copy link
Member

This would require type information, so it would only be possible when typescript-eslint's parser is used.

Other patterns that should be reported:

(maybeRef ? x : y)
!maybeRef

maybeRef || x
maybeRef && y
maybeRef ?? x

x || maybeRef
x && maybeRef
x ?? maybeRef

maybeRef == x
maybeRef != x
maybeRef === x
maybeRef !== x

x == maybeRef
x != maybeRef
x === maybeRef
x !== maybeRef

Boolean(maybeRef)
String(maybeRef)

As a name, I'd suggest vue/require-mayberef-unwrap

Similar to

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

No branches or pull requests

2 participants