Skip to content

Commit b940cb9

Browse files
authored
Add vue/no-deprecated-html-element-is rule (#1117)
1 parent fd6b3e1 commit b940cb9

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
4242
| [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: |
4343
| [vue/no-deprecated-events-api](./no-deprecated-events-api.md) | disallow using deprecated events api (in Vue.js 3.0.0+) | |
4444
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax (in Vue.js 3.0.0+) | |
45+
| [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+) | |
4546
| [vue/no-deprecated-inline-template](./no-deprecated-inline-template.md) | disallow using deprecated `inline-template` attribute (in Vue.js 3.0.0+) | |
4647
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
4748
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-html-element-is
5+
description: disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)
6+
---
7+
# vue/no-deprecated-html-element-is
8+
> disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)
9+
10+
- :gear: This rule is included in all of `"plugin:vue/vue3-essential"`, `"plugin:vue/vue3-strongly-recommended"` and `"plugin:vue/vue3-recommended"`.
11+
12+
## :book: Rule Details
13+
14+
This rule reports deprecated the `is` attribute on HTML elements (removed in Vue.js v3.0.0+)
15+
16+
<eslint-code-block :rules="{'vue/no-deprecated-html-element-is': ['error']}">
17+
18+
```vue
19+
<template>
20+
<!-- ✓ GOOD -->
21+
<div />
22+
<component is="foo">
23+
24+
<!-- ✗ BAD -->
25+
<div is="foo" />
26+
<div :is="foo" />
27+
</template>
28+
```
29+
30+
</eslint-code-block>
31+
32+
### :wrench: Options
33+
34+
Nothing.
35+
36+
## :books: Further Reading
37+
38+
- [Vue RFCs - 0027-custom-elements-interop](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0027-custom-elements-interop.md)
39+
40+
## :mag: Implementation
41+
42+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-html-element-is.js)
43+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-html-element-is.js)

lib/configs/vue3-essential.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
'vue/no-deprecated-data-object-declaration': 'error',
1111
'vue/no-deprecated-events-api': 'error',
1212
'vue/no-deprecated-filter': 'error',
13+
'vue/no-deprecated-html-element-is': 'error',
1314
'vue/no-deprecated-inline-template': 'error',
1415
'vue/no-deprecated-scope-attribute': 'error',
1516
'vue/no-deprecated-slot-attribute': 'error',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
'no-deprecated-data-object-declaration': require('./rules/no-deprecated-data-object-declaration'),
4444
'no-deprecated-events-api': require('./rules/no-deprecated-events-api'),
4545
'no-deprecated-filter': require('./rules/no-deprecated-filter'),
46+
'no-deprecated-html-element-is': require('./rules/no-deprecated-html-element-is'),
4647
'no-deprecated-inline-template': require('./rules/no-deprecated-inline-template'),
4748
'no-deprecated-scope-attribute': require('./rules/no-deprecated-scope-attribute'),
4849
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @author Yosuke Ota
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const utils = require('../utils')
12+
13+
// ------------------------------------------------------------------------------
14+
// Rule Definition
15+
// ------------------------------------------------------------------------------
16+
17+
module.exports = {
18+
meta: {
19+
type: 'problem',
20+
docs: {
21+
description: 'disallow using deprecated the `is` attribute on HTML elements (in Vue.js 3.0.0+)',
22+
categories: ['vue3-essential'],
23+
url: 'https://eslint.vuejs.org/rules/no-deprecated-html-element-is.html'
24+
},
25+
fixable: null,
26+
schema: [],
27+
messages: {
28+
unexpected: 'The `is` attribute on HTML element are deprecated.'
29+
}
30+
},
31+
32+
create: function (context) {
33+
return utils.defineTemplateBodyVisitor(context, {
34+
"VAttribute[directive=true][key.name.name='bind'][key.argument.name='is'], VAttribute[directive=false][key.name='is']" (node) {
35+
const element = node.parent.parent
36+
if (
37+
!utils.isHtmlWellKnownElementName(element.rawName) &&
38+
!utils.isSvgWellKnownElementName(element.rawName)
39+
) {
40+
return
41+
}
42+
context.report({
43+
node,
44+
loc: node.loc,
45+
messageId: 'unexpected'
46+
})
47+
}
48+
})
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* @author Yosuke Ota
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Requirements
9+
// ------------------------------------------------------------------------------
10+
11+
const rule = require('../../../lib/rules/no-deprecated-html-element-is')
12+
const RuleTester = require('eslint').RuleTester
13+
14+
// ------------------------------------------------------------------------------
15+
// Tests
16+
// ------------------------------------------------------------------------------
17+
18+
const ruleTester = new RuleTester({
19+
parser: require.resolve('vue-eslint-parser'),
20+
parserOptions: { ecmaVersion: 2019 }
21+
})
22+
23+
ruleTester.run('no-deprecated-inline-template', rule, {
24+
valid: [
25+
{
26+
filename: 'test.vue',
27+
code: '<template><component is="foo" /></template>'
28+
},
29+
{
30+
filename: 'test.vue',
31+
code: '<template><div /></template>'
32+
},
33+
{
34+
filename: 'test.vue',
35+
code: '<template><Foo is="foo" /></template>'
36+
},
37+
{
38+
filename: 'test.vue',
39+
code: '<template><component :is="\'foo\'" /></template>'
40+
}
41+
],
42+
43+
invalid: [
44+
{
45+
filename: 'test.vue',
46+
code: '<template><div is="foo" /></template>',
47+
errors: [
48+
{
49+
line: 1,
50+
column: 16,
51+
messageId: 'unexpected',
52+
endLine: 1,
53+
endColumn: 24
54+
}
55+
]
56+
},
57+
{
58+
filename: 'test.vue',
59+
code: '<template><div :is="foo" /></template>',
60+
errors: [
61+
{
62+
line: 1,
63+
column: 16,
64+
messageId: 'unexpected'
65+
}
66+
]
67+
}
68+
]
69+
})

0 commit comments

Comments
 (0)