Skip to content

vue/prefer-use-template-ref does not work with multiple script blocks #2696

Closed
@doominator42

Description

@doominator42

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.21.0
  • eslint-plugin-vue version: 9.32.0
  • Vue version: 3.5.13
  • Node version: 23.9.0
  • Operating System: Arch Linux

Please show your full configuration:

import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'

export default [
  {
    name: 'app/files-to-lint',
    files: ['**/*.{js,mjs,jsx,vue}'],
  },

  {
    name: 'app/files-to-ignore',
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
  },

  js.configs.recommended,
  ...pluginVue.configs['flat/essential'],
  {
    rules: {
      'vue/prefer-use-template-ref': 'error'
    }
  }
]

What did you do?

<template>
  <div ref="root" :data-a="A" />
</template>

<script>
const A = 'foo'
</script>

<script setup>
import { ref } from 'vue'
const root = ref()
</script>

What did you expect to happen?
Eslint should report an error for the rule vue/prefer-use-template-ref.

What actually happened?

No errors are reported, it does not detect the ref when there is multiple <script> in the same file. If I remove the first <script> block, it reports the error. The bug also occurs with two <script setup> and the order of the blocks does not matter, as soon as there is more than one <script>, the rule stops working.

Repository to reproduce this issue

https://github.com/doominator42/vue-eslint-use-template-ref-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions