-
-
Notifications
You must be signed in to change notification settings - Fork 663
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-v-is
rule (#1510)
- Loading branch information
Showing
5 changed files
with
111 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,42 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-deprecated-v-is | ||
description: disallow deprecated `v-is` directive (in Vue.js 3.1.0+) | ||
--- | ||
# vue/no-deprecated-v-is | ||
|
||
> disallow deprecated `v-is` directive (in Vue.js 3.1.0+) | ||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports deprecated `v-is` directive in Vue.js v3.1.0+. | ||
|
||
Use [`is` attribute with `vue:` prefix](https://v3.vuejs.org/api/special-attributes.html#is) instead. | ||
|
||
<eslint-code-block fix :rules="{'vue/no-deprecated-v-is': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<!-- ✓ GOOD --> | ||
<div is="vue:MyComponent" /> | ||
<component is="MyComponent" /> | ||
<!-- ✗ BAD --> | ||
<div v-is="'MyComponent'" /> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :books: Further Reading | ||
|
||
- [v-is](https://v3.vuejs.org/api/directives.html#v-is) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-v-is.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-v-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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const utils = require('../utils') | ||
const vIs = require('./syntaxes/v-is') | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'disallow deprecated `v-is` directive (in Vue.js 3.1.0+)', | ||
// TODO Switch to `vue3-essential` in the major version. | ||
// categories: ['vue3-essential'], | ||
categories: undefined, | ||
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-is.html' | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
forbiddenVIs: '`v-is` directive is deprecated.' | ||
} | ||
}, | ||
/** @param {RuleContext} context */ | ||
create(context) { | ||
const templateBodyVisitor = vIs.createTemplateBodyVisitor(context) | ||
return utils.defineTemplateBodyVisitor(context, templateBodyVisitor) | ||
} | ||
} |
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,36 @@ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/no-deprecated-v-is') | ||
|
||
const tester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { | ||
ecmaVersion: 2015 | ||
} | ||
}) | ||
|
||
tester.run('no-deprecated-v-is', rule, { | ||
valid: [ | ||
`<template> | ||
<div is="vue:MyComponent" /> | ||
</template>`, | ||
`<template> | ||
<component is="MyComponent" /> | ||
</template>` | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div v-is="'MyComponent'" /> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: '`v-is` directive is deprecated.', | ||
line: 3 | ||
} | ||
] | ||
} | ||
] | ||
}) |