-
-
Notifications
You must be signed in to change notification settings - Fork 694
Add autofix to vue/prefer-use-template-ref
#2632
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
Changes from 1 commit
ac5aa92
fe49694
d7331ac
00c9c0e
7db1382
c8bb2e0
f6aefde
e1ea60f
ff2ba97
d201c21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ function addUseTemplateRefImport(context, fixer) { | |
} | ||
|
||
const body = sourceCode.ast.body | ||
|
||
const imports = body.filter((node) => node.type === 'ImportDeclaration') | ||
|
||
const vueDestructuredImport = imports.find( | ||
|
@@ -79,13 +78,12 @@ function addUseTemplateRefImport(context, fixer) { | |
const lastImportSpecifier = importSpecifiers[importSpecifiers.length - 1] | ||
|
||
// @ts-ignore | ||
return fixer.insertTextAfter(lastImportSpecifier, `,useTemplateRef`) | ||
return fixer.insertTextAfter(lastImportSpecifier, `,useTemplateRef`) | ||
} | ||
|
||
const importStatement = "import { useTemplateRef } from 'vue';" | ||
const lastImport = imports[imports.length - 1] | ||
|
||
const importStatement = "import {useTemplateRef} from 'vue';" | ||
|
||
if (lastImport) { | ||
const indent = createIndent(lastImport) | ||
|
||
|
@@ -168,16 +166,11 @@ module.exports = { | |
name: scriptRef.node?.callee?.name | ||
}, | ||
fix(fixer) { | ||
/** @type {Fix[]} */ | ||
const fixes = [] | ||
|
||
const replaceFunctionFix = fixer.replaceText( | ||
scriptRef.node, | ||
`useTemplateRef('${scriptRef.ref}')` | ||
) | ||
|
||
fixes.push(replaceFunctionFix) | ||
|
||
if (!missingImportChecked) { | ||
missingImportChecked = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this flag for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Thomasan1999 it would be great to get this merged. Could you please have a look into this? |
||
|
||
|
@@ -187,11 +180,11 @@ module.exports = { | |
) | ||
|
||
if (missingImportFix) { | ||
fixes.push(missingImportFix) | ||
return [replaceFunctionFix, missingImportFix] | ||
} | ||
} | ||
|
||
return fixes | ||
return replaceFunctionFix | ||
} | ||
}) | ||
} | ||
|