Skip to content

ESLint rules not enforced in Vue template sections (only in script tags) #619

@mgambella

Description

@mgambella

Environment



Package

@nuxt/eslint

Reproduction

Configuration

eslint.config.mjs :

js
// @ts-check
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt()

Example File
In ColorPicker.vue:

vue
<script setup lang="ts">
// ... other code ...

// ✅ This IS detected by ESLint when running `pnpm lint:fix`
const aVar = 'pol' as any  // Line 119
</script>

<template>
  <div>
    <!-- ... other template code ... -->
    
    <!-- ❌ This is NOT detected by ESLint when running `pnpm lint:fix` -->
    <div
      class="ml-3 block h-full w-28 rounded-full sm:w-36"
      :class="optionValue(option as any) ? '' : 'border'"  <!-- Line 188 -->
    >
      &nbsp;
    </div>
  </div>
</template>

Steps to Reproduce

1. Create a Vue component with TypeScript
2. Add as any type assertion in the <script> section
3. Add as any type assertion in the <template> section (e.g., in a binding expression)
4. Run pnpm lint:fix or eslint .
5. Observe that only the script violation is caught

🤔 Expected Behavior

ESLint should enforce TypeScript rules (like @typescript-eslint/no-explicit-any) in both <script> and sections of Vue SFC files.

📊 Current Behavior

- TypeScript ESLint rules work in <script> tags ✅
- TypeScript ESLint rules are ignored in <template> tags ❌

Describe the bug

🐛 Bug Report

ESLint rules are not being enforced in Vue template sections, while they work correctly in <script> tags. Specifically, the @typescript-eslint/no-explicit-any rule (or similar TypeScript rules) is not catching violations in template expressions.

Additional context

❓ Questions

  • Is this expected behavior, or is there additional configuration needed to enable TypeScript linting in Vue templates?
  • Should I configure something specific in eslint.config.mjs, and/or nuxt.config.ts, to enable template expression linting?
  • Are there any known limitations with the flat config format and Vue template linting?

Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions