123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 'use strict'
- const utils = require('../utils')
- module.exports = {
- meta: {
- type: 'problem',
- docs: {
- description: 'disallow `key` attribute on `<template>`',
- categories: ['vue3-essential', 'essential'],
- url: 'https://eslint.vuejs.org/rules/no-template-key.html'
- },
- fixable: null,
- schema: [],
- messages: {
- disallow:
- "'<template>' cannot be keyed. Place the key on real elements instead."
- }
- },
-
- create(context) {
- return utils.defineTemplateBodyVisitor(context, {
-
- "VElement[name='template']"(node) {
- const keyNode =
- utils.getAttribute(node, 'key') ||
- utils.getDirective(node, 'bind', 'key')
- if (keyNode) {
- if (utils.hasDirective(node, 'for')) {
-
-
-
- return
- }
- context.report({
- node: keyNode,
- loc: keyNode.loc,
- messageId: 'disallow'
- })
- }
- }
- })
- }
- }
|