Skip to content

Commit 96712ba

Browse files
authored
New: Add vue/no-deprecated-inline-template rule (#1100)
1 parent 3e90a0c commit 96712ba

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
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-events-api](./no-deprecated-events-api.md) | disallow using deprecated events api | |
4343
| [vue/no-deprecated-data-object-declaration](./no-deprecated-data-object-declaration.md) | disallow using deprecated object declaration on data | :wrench: |
4444
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax | |
45+
| [vue/no-deprecated-inline-template](./no-deprecated-inline-template.md) | disallow using deprecated `inline-template` attribute | |
4546
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
4647
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
4748
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-inline-template
5+
description: disallow using deprecated `inline-template` attribute
6+
---
7+
# vue/no-deprecated-inline-template
8+
> disallow using deprecated `inline-template` attribute
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 `inline-template` attributes (removed in Vue.js v3.0.0+)
15+
16+
<eslint-code-block :rules="{'vue/no-deprecated-inline-template': ['error']}">
17+
18+
```vue
19+
<template>
20+
<!-- ✓ GOOD -->
21+
<my-comnponent />
22+
23+
<!-- ✗ BAD -->
24+
<my-component inline-template>
25+
<div>
26+
<p>These are compiled as the component's own template.</p>
27+
<p>Not parent's transclusion content.</p>
28+
</div>
29+
</my-component>
30+
</template>
31+
```
32+
33+
</eslint-code-block>
34+
35+
### :wrench: Options
36+
37+
Nothing.
38+
39+
## :books: Further Reading
40+
41+
- [Vue RFCs - 0016-remove-inline-templates](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0016-remove-inline-templates.md)
42+
43+
## :mag: Implementation
44+
45+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-inline-template.js)
46+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-inline-template.js)

lib/configs/vue3-essential.js

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

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = {
4343
'no-deprecated-events-api': require('./rules/no-deprecated-events-api'),
4444
'no-deprecated-data-object-declaration': require('./rules/no-deprecated-data-object-declaration'),
4545
'no-deprecated-filter': require('./rules/no-deprecated-filter'),
46+
'no-deprecated-inline-template': require('./rules/no-deprecated-inline-template'),
4647
'no-deprecated-scope-attribute': require('./rules/no-deprecated-scope-attribute'),
4748
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
4849
'no-deprecated-slot-scope-attribute': require('./rules/no-deprecated-slot-scope-attribute'),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 `inline-template` attribute',
22+
categories: ['vue3-essential'],
23+
url: 'https://eslint.vuejs.org/rules/no-deprecated-inline-template.html'
24+
},
25+
fixable: null,
26+
schema: [],
27+
messages: {
28+
unexpected: '`inline-template` are deprecated.'
29+
}
30+
},
31+
32+
create: function (context) {
33+
return utils.defineTemplateBodyVisitor(context, {
34+
"VAttribute[directive=false] > VIdentifier[rawName='inline-template']" (node) {
35+
context.report({
36+
node,
37+
loc: node.loc,
38+
messageId: 'unexpected'
39+
})
40+
}
41+
})
42+
}
43+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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-inline-template')
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><my-component><div /></my-component></template>'
28+
},
29+
{
30+
filename: 'test.vue',
31+
code: '<template><div /></template>'
32+
},
33+
{
34+
filename: 'test.vue',
35+
code: '<template><my-component :inline-template="foo"><div /></my-component></template>'
36+
},
37+
{
38+
filename: 'test.vue',
39+
code: '<template><my-component Inline-Template="foo"><div /></my-component></template>'
40+
}
41+
],
42+
43+
invalid: [
44+
{
45+
filename: 'test.vue',
46+
code: '<template><my-component inline-template><div /></my-component></template>',
47+
errors: [
48+
{
49+
line: 1,
50+
column: 25,
51+
messageId: 'unexpected',
52+
endLine: 1,
53+
endColumn: 40
54+
}
55+
]
56+
},
57+
{
58+
filename: 'test.vue',
59+
code: '<template><my-component inline-template=""><div /></my-component></template>',
60+
errors: [{ messageId: 'unexpected' }]
61+
},
62+
{
63+
filename: 'test.vue',
64+
code: '<template><my-component inline-template="foo"><div /></my-component></template>',
65+
errors: [{ messageId: 'unexpected' }]
66+
}
67+
]
68+
})

0 commit comments

Comments
 (0)