Skip to content

Rule "vue/valid-template-root" should be disabled for slot templates #621

@IvoPereira

Description

@IvoPereira

Tell us about your environment

  • ESLint Version: 4.19.1
  • eslint-plugin-vue Version: 4.7.1
  • Node Version: v10.6.0

Please show your full configuration:

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    "eslint:recommended",
    '@vue/airbnb'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-unused-vars': [2, {'args': 'after-used', 'argsIgnorePattern': '^_'}],
    'no-param-reassign': [2, {'props': false}]
  },
  parserOptions: {
    parser: 'babel-eslint',
    "ecmaVersion": 8,
    "ecmaFeatures": {
      "impliedStrict": true,
      "classes": true
    }
  },
}

What did you do? Please include the actual source code causing the issue.

<template>
  <v-select
    class="elevation-0"
    label="Not being sorted"
    :items="employees"
    v-model="buy.sorter_id"
    item-text="full_name"
    item-value="id"
    dense
    solo
    clearable
    @input="handleSelectInput"
  >
    <template slot="selection" slot-scope="data">
      <v-flex xs2>
        <v-avatar size="25px">
          <img :src="data.item.safe_avatar_url"/>
        </v-avatar>
      </v-flex>
      <v-flex class='ml-1'>
        {{ data.item.full_name }}
      </v-flex>
    </template>
    <template slot="item" slot-scope="data">
      <v-list-tile-avatar>
        <img :src="data.item.safe_avatar_url" />
      </v-list-tile-avatar>
      <v-list-tile-content>
        <v-list-tile-title v-html="data.item.full_name"></v-list-tile-title>
      </v-list-tile-content>
    </template>
  </v-select>
</template>

What did you expect to happen?

I expected the code to run without warnings.

What actually happened? Please include the actual, raw output from ESLint.

[eslint-plugin-vue]
[vue/valid-template-root]
The template root requires exactly one element.

This refers to the valid-template-root on the inner slot template snippet:

    <template slot="item" slot-scope="data">
      <v-list-tile-avatar>
        <img :src="data.item.safe_avatar_url" />
      </v-list-tile-avatar>
      <v-list-tile-content>
        <v-list-tile-title v-html="data.item.full_name"></v-list-tile-title>
      </v-list-tile-content>
    </template>

The rule shouldn't catch a slot template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions