Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork700
feat(no-ref-as-operand): support ref detection from composable functions#2954
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
kzhrk wants to merge1 commit intovuejs:masterChoose a base branch fromkzhrk:issue-2519
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+285 −0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Implement comprehensive support for detecting ref objects returned from composable functionsin the no-ref-as-operand rule. This enhancement includes:Type Information Foundation:- Add utility functions to detect functions that return Ref objects- checkFunctionReturnsRef(): Analyzes function bodies for ref returns- isRefCall(): Recursively checks for ref() calls in various patterns- Support for multiple return patterns: * Direct ref() calls: return ref(0) * Object properties: return { data: ref(0) } * Array elements: return [ref(0)]Composable Function Detection:- Implement processComposableRefCall() method for handling composable function calls- Build map of ref-returning functions via body analysis (not JSDoc)- Detect variable assignments from composable function calls- Properly handle all scope contexts, not just global scope- Generate appropriate error messages showing composable function namesTesting:- Add 6 new test cases covering composable function ref detection- Test valid usage with proper .value access- Test invalid usage without .value access- All 55 tests pass (49 existing + 6 new)This approach is more robust than JSDoc detection as it analyzes actual code structureand works reliably in test environments.🦋 Changeset detectedLatest commit:2507cc9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means?Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes#2519
Summary
Extends the
vue/no-ref-as-operandrule to detect and report when ref objectsreturned from composable functions are used without accessing the
.valueproperty.Previously, the rule only detected direct ref declarations like
ref(0).Now it also detects ref objects returned from composable functions:
Motivation
Composable functions are a common pattern in Vue 3 for code reuse. When they return
Ref objects, developers should use the .value property to access the wrapped value.
However, the rule previously had no way to detect when these composable-returned refs
were used incorrectly.
This enhancement provides early feedback to developers, helping them follow Vue 3
best practices and preventing subtle bugs.
Implementation Details
Scope and Limitations
The detection works for composable functions defined in the same file. Due to
ESLint's single-file analysis model, composable functions imported from external
modules cannot be analyzed. This is a fundamental ESLint framework constraint.
Testing