Skip to content

Commit

Permalink
Add vue/no-deprecated-html-element-is rule (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 9, 2020
1 parent fd6b3e1 commit b940cb9
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -42,6 +42,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| [vue/no-deprecated-data-object-declaration](./no-deprecated-data-object-declaration.md) | disallow using deprecated object declaration on data (in Vue.js 3.0.0+) | :wrench: |
| [vue/no-deprecated-events-api](./no-deprecated-events-api.md) | disallow using deprecated events api (in Vue.js 3.0.0+) | |
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax (in Vue.js 3.0.0+) | |
| [vue/no-deprecated-html-element-is](./no-deprecated-html-element-is.md) | disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+) | |
| [vue/no-deprecated-inline-template](./no-deprecated-inline-template.md) | disallow using deprecated `inline-template` attribute (in Vue.js 3.0.0+) | |
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
Expand Down
43 changes: 43 additions & 0 deletions docs/rules/no-deprecated-html-element-is.md
@@ -0,0 +1,43 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-deprecated-html-element-is
description: disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)
---
# vue/no-deprecated-html-element-is
> disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`.

## :book: Rule Details

This rule reports deprecated the `is` attribute on HTML elements (removed in Vue.js v3.0.0+)

<eslint-code-block :rules="{'vue/no-deprecated-html-element-is': ['error']}">

```vue
<template>
<!-- ✓ GOOD -->
<div />
<component is="foo">
<!-- ✗ BAD -->
<div is="foo" />
<div :is="foo" />
</template>
```

</eslint-code-block>

### :wrench: Options

Nothing.

## :books: Further Reading

- [Vue RFCs - 0027-custom-elements-interop](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0027-custom-elements-interop.md)

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-html-element-is.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-html-element-is.js)
1 change: 1 addition & 0 deletions lib/configs/vue3-essential.js
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'vue/no-deprecated-data-object-declaration': 'error',
'vue/no-deprecated-events-api': 'error',
'vue/no-deprecated-filter': 'error',
'vue/no-deprecated-html-element-is': 'error',
'vue/no-deprecated-inline-template': 'error',
'vue/no-deprecated-scope-attribute': 'error',
'vue/no-deprecated-slot-attribute': 'error',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -43,6 +43,7 @@ module.exports = {
'no-deprecated-data-object-declaration': require('./rules/no-deprecated-data-object-declaration'),
'no-deprecated-events-api': require('./rules/no-deprecated-events-api'),
'no-deprecated-filter': require('./rules/no-deprecated-filter'),
'no-deprecated-html-element-is': require('./rules/no-deprecated-html-element-is'),
'no-deprecated-inline-template': require('./rules/no-deprecated-inline-template'),
'no-deprecated-scope-attribute': require('./rules/no-deprecated-scope-attribute'),
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
Expand Down
50 changes: 50 additions & 0 deletions lib/rules/no-deprecated-html-element-is.js
@@ -0,0 +1,50 @@
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const utils = require('../utils')

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)',
categories: ['vue3-essential'],
url: 'https://eslint.vuejs.org/rules/no-deprecated-html-element-is.html'
},
fixable: null,
schema: [],
messages: {
unexpected: 'The `is` attribute on HTML element are deprecated.'
}
},

create: function (context) {
return utils.defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name.name='bind'][key.argument.name='is'], VAttribute[directive=false][key.name='is']" (node) {
const element = node.parent.parent
if (
!utils.isHtmlWellKnownElementName(element.rawName) &&
!utils.isSvgWellKnownElementName(element.rawName)
) {
return
}
context.report({
node,
loc: node.loc,
messageId: 'unexpected'
})
}
})
}
}
69 changes: 69 additions & 0 deletions tests/lib/rules/no-deprecated-html-element-is.js
@@ -0,0 +1,69 @@
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-deprecated-html-element-is')
const RuleTester = require('eslint').RuleTester

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: { ecmaVersion: 2019 }
})

ruleTester.run('no-deprecated-inline-template', rule, {
valid: [
{
filename: 'test.vue',
code: '<template><component is="foo" /></template>'
},
{
filename: 'test.vue',
code: '<template><div /></template>'
},
{
filename: 'test.vue',
code: '<template><Foo is="foo" /></template>'
},
{
filename: 'test.vue',
code: '<template><component :is="\'foo\'" /></template>'
}
],

invalid: [
{
filename: 'test.vue',
code: '<template><div is="foo" /></template>',
errors: [
{
line: 1,
column: 16,
messageId: 'unexpected',
endLine: 1,
endColumn: 24
}
]
},
{
filename: 'test.vue',
code: '<template><div :is="foo" /></template>',
errors: [
{
line: 1,
column: 16,
messageId: 'unexpected'
}
]
}
]
})

0 comments on commit b940cb9

Please sign in to comment.