caece2b46a0072b91dcd5d040464be6448e9c1a95cf7ca6c7375cc21f0eaabb7e38daa2b308a4c231e388531c79f0a192eb2bffb1abecfb01fa01c12404f63 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * @author Toru Nagashima
  3. * @copyright 2017 Toru Nagashima. All rights reserved.
  4. * See LICENSE file in root directory for full license.
  5. */
  6. 'use strict'
  7. // ------------------------------------------------------------------------------
  8. // Requirements
  9. // ------------------------------------------------------------------------------
  10. const utils = require('../utils')
  11. // ------------------------------------------------------------------------------
  12. // Rule Definition
  13. // ------------------------------------------------------------------------------
  14. module.exports = {
  15. meta: {
  16. type: 'suggestion',
  17. docs: {
  18. description: 'enforce end tag style',
  19. categories: ['vue3-strongly-recommended', 'strongly-recommended'],
  20. url: 'https://eslint.vuejs.org/rules/html-end-tags.html'
  21. },
  22. fixable: 'code',
  23. schema: []
  24. },
  25. /** @param {RuleContext} context */
  26. create(context) {
  27. let hasInvalidEOF = false
  28. return utils.defineTemplateBodyVisitor(
  29. context,
  30. {
  31. VElement(node) {
  32. if (hasInvalidEOF) {
  33. return
  34. }
  35. const name = node.name
  36. const isVoid = utils.isHtmlVoidElementName(name)
  37. const isSelfClosing = node.startTag.selfClosing
  38. const hasEndTag = node.endTag != null
  39. if (!isVoid && !hasEndTag && !isSelfClosing) {
  40. context.report({
  41. node: node.startTag,
  42. loc: node.startTag.loc,
  43. message: "'<{{name}}>' should have end tag.",
  44. data: { name },
  45. fix: (fixer) => fixer.insertTextAfter(node, `</${name}>`)
  46. })
  47. }
  48. }
  49. },
  50. {
  51. Program(node) {
  52. hasInvalidEOF = utils.hasInvalidEOF(node)
  53. }
  54. }
  55. )
  56. }
  57. }