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-scope-attribute rule (#838)
- Loading branch information
1 parent
ff6b275
commit 9f2cec1
Showing
6 changed files
with
205 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,47 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-deprecated-scope-attribute | ||
description: disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | ||
--- | ||
# vue/no-deprecated-scope-attribute | ||
> disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | ||
- :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 `scope` attribute in Vue.js v2.5.0+. | ||
|
||
<eslint-code-block fix :rules="{'vue/no-deprecated-scope-attribute': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<ListComponent> | ||
<!-- ✓ GOOD --> | ||
<template v-slot:name="props"> | ||
{{ props.title }} | ||
</template> | ||
<template slot="name" slot-scope="props"> | ||
{{ props.title }} | ||
</template> | ||
</ListComponent> | ||
<ListComponent> | ||
<!-- ✗ BAD --> | ||
<template slot="name" scope="props"> | ||
{{ props.title }} | ||
</template> | ||
</ListComponent> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
## :books: Further reading | ||
|
||
- [API - scope](https://vuejs.org/v2/api/#scope-removed) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-scope-attribute.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-scope-attribute.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,28 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const utils = require('../utils') | ||
const scopeAttribute = require('./syntaxes/scope-attribute') | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'disallow deprecated `scope` attribute (in Vue.js 2.5.0+)', | ||
category: undefined, | ||
url: 'https://eslint.vuejs.org/rules/no-deprecated-scope-attribute.html' | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
forbiddenScopeAttribute: '`scope` attributes are deprecated.' | ||
} | ||
}, | ||
create (context) { | ||
const templateBodyVisitor = scopeAttribute.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,27 @@ | ||
/** | ||
* @author Yosuke Ota | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
module.exports = { | ||
deprecated: '2.5.0', | ||
createTemplateBodyVisitor (context) { | ||
/** | ||
* Reports `scope` node | ||
* @param {VDirectiveKey} scopeKey node of `scope` | ||
* @returns {void} | ||
*/ | ||
function reportScope (scopeKey) { | ||
context.report({ | ||
node: scopeKey, | ||
messageId: 'forbiddenScopeAttribute', | ||
// fix to use `slot-scope` | ||
fix: fixer => fixer.replaceText(scopeKey, 'slot-scope') | ||
}) | ||
} | ||
|
||
return { | ||
"VAttribute[directive=true] > VDirectiveKey[name.name='scope']": reportScope | ||
} | ||
} | ||
} |
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,101 @@ | ||
'use strict' | ||
|
||
const RuleTester = require('eslint').RuleTester | ||
const rule = require('../../../lib/rules/no-deprecated-scope-attribute') | ||
|
||
const tester = new RuleTester({ | ||
parser: 'vue-eslint-parser', | ||
parserOptions: { | ||
ecmaVersion: 2015 | ||
} | ||
}) | ||
|
||
tester.run('no-deprecated-scope-attribute', rule, { | ||
valid: [ | ||
`<template> | ||
<LinkList> | ||
<a v-slot:name /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a #name /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a v-slot="{a}" /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a #default="{a}" /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a slot="name" /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a slot-scope="{a}" /> | ||
</LinkList> | ||
</template>`, | ||
`<template> | ||
<LinkList> | ||
<a /> | ||
</LinkList> | ||
</template>` | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<LinkList> | ||
<template scope="{a}"> | ||
<a /> | ||
</template> | ||
</LinkList> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<LinkList> | ||
<template slot-scope="{a}"> | ||
<a /> | ||
</template> | ||
</LinkList> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: '`scope` attributes are deprecated.', | ||
line: 4 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<LinkList> | ||
<template slot="name" scope="{a}"> | ||
<a /> | ||
</template> | ||
</LinkList> | ||
</template>`, | ||
output: ` | ||
<template> | ||
<LinkList> | ||
<template slot="name" slot-scope="{a}"> | ||
<a /> | ||
</template> | ||
</LinkList> | ||
</template>`, | ||
errors: [ | ||
{ | ||
message: '`scope` attributes are deprecated.', | ||
line: 4 | ||
} | ||
] | ||
} | ||
] | ||
}) |