no-deprecated-html-element-is.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @author Yosuke Ota
  3. * See LICENSE file in root directory for full license.
  4. */
  5. 'use strict'
  6. const utils = require('../utils')
  7. module.exports = {
  8. meta: {
  9. type: 'problem',
  10. docs: {
  11. description:
  12. 'disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)',
  13. categories: ['vue3-essential'],
  14. url: 'https://eslint.vuejs.org/rules/no-deprecated-html-element-is.html'
  15. },
  16. fixable: null,
  17. schema: [],
  18. messages: {
  19. unexpected: 'The `is` attribute on HTML element are deprecated.'
  20. }
  21. },
  22. /** @param {RuleContext} context */
  23. create(context) {
  24. /** @param {VElement} node */
  25. function isValidElement(node) {
  26. return (
  27. !utils.isHtmlWellKnownElementName(node.rawName) &&
  28. !utils.isSvgWellKnownElementName(node.rawName) &&
  29. !utils.isMathWellKnownElementName(node.rawName)
  30. )
  31. }
  32. return utils.defineTemplateBodyVisitor(context, {
  33. /** @param {VDirective} node */
  34. "VAttribute[directive=true][key.name.name='bind'][key.argument.name='is']"(
  35. node
  36. ) {
  37. if (isValidElement(node.parent.parent)) {
  38. return
  39. }
  40. context.report({
  41. node,
  42. loc: node.loc,
  43. messageId: 'unexpected'
  44. })
  45. },
  46. /** @param {VAttribute} node */
  47. "VAttribute[directive=false][key.name='is']"(node) {
  48. if (isValidElement(node.parent.parent)) {
  49. return
  50. }
  51. if (node.value && node.value.value.startsWith('vue:')) {
  52. // Usage on native elements 3.1+
  53. return
  54. }
  55. context.report({
  56. node,
  57. loc: node.loc,
  58. messageId: 'unexpected'
  59. })
  60. }
  61. })
  62. }
  63. }