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

feat: add prefer-use-template-ref rule #2554

Merged
merged 20 commits into from
Nov 11, 2024
Merged
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 fix function
  • Loading branch information
Thomasan1999 committed Nov 2, 2024
commit 329e9ac188bedb8255370aab00e9013d6f7ed2a9
2 changes: 1 addition & 1 deletion docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ For example:
| [vue/prefer-prop-type-boolean-first](./prefer-prop-type-boolean-first.md) | enforce `Boolean` comes first in component prop types | :bulb: | :warning: |
| [vue/prefer-separate-static-class](./prefer-separate-static-class.md) | require static class names in template to be in a separate `class` attribute | :wrench: | :hammer: |
| [vue/prefer-true-attribute-shorthand](./prefer-true-attribute-shorthand.md) | require shorthand form attribute when `v-bind` value is `true` | :bulb: | :hammer: |
| [vue/prefer-use-template-ref](./prefer-use-template-ref.md) | require using `useTemplateRef` instead of `ref` for template refs | :wrench: | :hammer: |
| [vue/prefer-use-template-ref](./prefer-use-template-ref.md) | require using `useTemplateRef` instead of `ref` for template refs | | :hammer: |
| [vue/require-default-export](./require-default-export.md) | require components to be the default export | | :warning: |
| [vue/require-direct-export](./require-direct-export.md) | require the component to be directly exported | | :hammer: |
| [vue/require-emit-validator](./require-emit-validator.md) | require type definitions in emits | :bulb: | :hammer: |
Expand Down
3 changes: 1 addition & 2 deletions docs/rules/prefer-use-template-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description: require using `useTemplateRef` instead of `ref` for template refs
> require using `useTemplateRef` instead of `ref` for template refs

- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> _**This rule has not been released yet.**_ </badge>
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.

## :book: Rule Details

Expand All @@ -19,7 +18,7 @@ the [`useTemplateRef()`](https://vuejs.org/guide/essentials/template-refs.html#a

This rule enforces using the new `useTemplateRef` function instead of `ref` for template refs.

<eslint-code-block fix :rules="{'vue/prefer-use-template-ref': ['error']}">
<eslint-code-block :rules="{'vue/prefer-use-template-ref': ['error']}">

```vue
<template>
Expand Down
9 changes: 1 addition & 8 deletions lib/rules/prefer-use-template-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module.exports = {
categories: undefined,
url: 'https://eslint.vuejs.org/rules/prefer-use-template-ref.html'
},
fixable: 'code',
schema: [],
messages: {
preferUseTemplateRef: "Replace 'ref' with 'useTemplateRef'."
Expand Down Expand Up @@ -74,13 +73,7 @@ module.exports = {

context.report({
node: scriptRef.node,
messageId: 'preferUseTemplateRef',
fix(fixer) {
return fixer.replaceText(
scriptRef.node,
`useTemplateRef('${scriptRef.ref}')`
)
}
messageId: 'preferUseTemplateRef'
})
}
}
Expand Down