-
-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add
vue/no-deprecated-inline-template
rule (#1100)
- Loading branch information
Showing
6 changed files
with
160 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,46 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-deprecated-inline-template | ||
description: disallow using deprecated `inline-template` attribute | ||
--- | ||
# vue/no-deprecated-inline-template | ||
> disallow using deprecated `inline-template` attribute | ||
- :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 `inline-template` attributes (removed in Vue.js v3.0.0+) | ||
|
||
<eslint-code-block :rules="{'vue/no-deprecated-inline-template': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<!-- ✓ GOOD --> | ||
<my-comnponent /> | ||
<!-- ✗ BAD --> | ||
<my-component inline-template> | ||
<div> | ||
<p>These are compiled as the component's own template.</p> | ||
<p>Not parent's transclusion content.</p> | ||
</div> | ||
</my-component> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
### :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :books: Further Reading | ||
|
||
- [Vue RFCs - 0016-remove-inline-templates](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0016-remove-inline-templates.md) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-inline-template.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-inline-template.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,43 @@ | ||
/** | ||
* @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 `inline-template` attribute', | ||
categories: ['vue3-essential'], | ||
url: 'https://eslint.vuejs.org/rules/no-deprecated-inline-template.html' | ||
}, | ||
fixable: null, | ||
schema: [], | ||
messages: { | ||
unexpected: '`inline-template` are deprecated.' | ||
} | ||
}, | ||
|
||
create: function (context) { | ||
return utils.defineTemplateBodyVisitor(context, { | ||
"VAttribute[directive=false] > VIdentifier[rawName='inline-template']" (node) { | ||
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,68 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-deprecated-inline-template') | ||
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><my-component><div /></my-component></template>' | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div /></template>' | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><my-component :inline-template="foo"><div /></my-component></template>' | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><my-component Inline-Template="foo"><div /></my-component></template>' | ||
} | ||
], | ||
|
||
invalid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><my-component inline-template><div /></my-component></template>', | ||
errors: [ | ||
{ | ||
line: 1, | ||
column: 25, | ||
messageId: 'unexpected', | ||
endLine: 1, | ||
endColumn: 40 | ||
} | ||
] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><my-component inline-template=""><div /></my-component></template>', | ||
errors: [{ messageId: 'unexpected' }] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><my-component inline-template="foo"><div /></my-component></template>', | ||
errors: [{ messageId: 'unexpected' }] | ||
} | ||
] | ||
}) |