Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
vue/no-deprecated-html-element-is
rule (#1117)
- Loading branch information
Showing
6 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
}) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
} | ||
] | ||
} | ||
] | ||
}) |