Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Thomasan1999 wants to merge 10 commits into vuejs:master
base: master
Choose a base branch
Loading
from Thomasan1999:master
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove util for retrieving the last element of array
  • Loading branch information
Thomasan1999 committed Nov 30, 2024
commit 7db13827e7204365bd31547d6fb7c049ddaa41ae
9 changes: 4 additions & 5 deletions lib/rules/prefer-use-template-ref.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ function addUseTemplateRefImport(context, fixer) {
)

if (vueDestructuredImport) {
const importSpecifierLast = utils.getLastArrayElement(
vueDestructuredImport.specifiers
)
const importSpecifiers = vueDestructuredImport.specifiers
const lastImportSpecifier = importSpecifiers[importSpecifiers.length - 1]

// @ts-ignore
return fixer.insertTextAfter(importSpecifierLast, `,useTemplateRef`)
return fixer.insertTextAfter(lastImportSpecifier, `,useTemplateRef`)
}

const lastImport = utils.getLastArrayElement(imports)
const lastImport = imports[imports.length - 1]

const importStatement = "import {useTemplateRef} from 'vue';"

Expand Down
10 changes: 0 additions & 10 deletions lib/utils/index.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2208,16 +2208,6 @@ module.exports = {
(token, i) =>
token.type === tokensR[i].type && token.value === tokensR[i].value
)
},

/**
* TODO: replace usages with 'array.at(-1)' once the minimum supported Node.js version is at least 16.6.0
* @template T
* @param array {T[]}
* @returns {T | undefined}
* */
getLastArrayElement(array) {
return array[array.length - 1]
}
}

Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /