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

Error for ref in condition #2140

Closed
maicss opened this issue Apr 26, 2023 · 4 comments
Closed

Error for ref in condition #2140

maicss opened this issue Apr 26, 2023 · 4 comments

Comments

@maicss
Copy link

maicss commented Apr 26, 2023

Please describe what the rule should do:

Should give an error when user use a ref value as condition assert.

What category should the rule belong to?

[ ] Enforces code style (layout)
[x] Warns about a potential error (problem)
[x] Suggests an alternate way of doing something (suggestion)
[ ] Other (please specify:)

Provide 2-3 code examples that this rule should warn about:

const someValue = ref(false)
// this condition always true, should give an error, suggest add `.value` after the variable
if (someValue) {

}
// should give an error too
[1, someValue].includes()
[1, someValue].some()
[1, someValue].every()

Additional context

No additional context

@maicss
Copy link
Author

maicss commented Apr 26, 2023

It seems we should not use ref without unref anywhere...like arguments for functions.
One exception: isRef(someValue). Am I right?

@jhoermann
Copy link

You should use @typescript-eslint/no-unnecessary-condition.

@FloEdelmann
Copy link
Member

A rule catching this is indeed hard to get right without TypeScript, so I'd also suggest @typescript-eslint/no-unnecessary-condition. Duplicating (part of) this rule in eslint-plugin-vue seems to be much work with little gain, while always missing some cases that should be reported.

@maicss
Copy link
Author

maicss commented Nov 22, 2024

Thanks! I will try this out.

@maicss maicss closed this as completed Nov 22, 2024
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

No branches or pull requests

3 participants