-
-
Notifications
You must be signed in to change notification settings - Fork 699
feat(prefer-template-ref): support auto-fix #2983
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
base: master
Are you sure you want to change the base?
Conversation
|
# Conflicts: # lib/rules/prefer-use-template-ref.js
FloEdelmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements auto-fix functionality for the prefer-use-template-ref rule, which automatically converts ref() and shallowRef() calls to useTemplateRef('name') when they are used as template refs. The implementation intentionally does not auto-import useTemplateRef to avoid conflicts with users who rely on unplugin-auto-import.
- Adds
fixable: 'code'metadata to enable auto-fixing - Implements fixer logic that correctly handles TypeScript type arguments/parameters
- Updates all test cases with expected outputs and enhanced error location information
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/rules/prefer-use-template-ref.js |
Adds fixable metadata and implements the fix function that replaces ref/shallowRef calls with useTemplateRef, preserving type arguments |
tests/lib/rules/prefer-use-template-ref.js |
Adds output expectations for all invalid test cases and includes endLine/endColumn in error assertions; adds TypeScript test case |
docs/rules/prefer-use-template-ref.md |
Adds wrench icon notation and fix attribute to code blocks to indicate auto-fix capability |
docs/rules/index.md |
Updates the rules table to show the wrench icon for this rule |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Re-implement of #2632 (closes #2632). (I really love this feature!)
But this PR doesn't insert
import { useTemplateRef } from 'vue'automatically.Because I think that falls outside the scope of this rule. Additionally, some users rely on
unplugin-auto-importand would have to remove the unnecessary import to maintain clean imports.Please merge #2982 first.