Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RFC0015): add no-deprecated-filter rule (#1043)
Co-authored-by: Yosuke Ota <otameshiyo23@gmail.com>
- Loading branch information
Showing
5 changed files
with
167 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,50 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/no-deprecated-filter | ||
description: disallow using deprecated filters syntax | ||
--- | ||
# vue/no-deprecated-filter | ||
> disallow using deprecated filters syntax | ||
|
||
## :book: Rule Details | ||
|
||
This rule reports deprecated `filters` syntax (removed in Vue.js v3.0.0+) | ||
|
||
<eslint-code-block :rules="{'vue/no-deprecated-filter': ['error']}"> | ||
|
||
```vue | ||
<template> | ||
<!-- ✓ GOOD --> | ||
{{ filter(msg) }} | ||
{{ filter(msg, '€') }} | ||
{{ filterB(filterA(msg)) }} | ||
<div v-bind:id="filter(msg)"></div> | ||
<div v-bind:id="filter(msg, '€')"></div> | ||
<div v-bind:id="filterB(filterA(msg))"></div> | ||
<!-- ✗ BAD --> | ||
{{ msg | filter }} | ||
{{ msg | filter('€') }} | ||
{{ msg | filterA | filterB }} | ||
<div v-bind:id="msg | filter"></div> | ||
<div v-bind:id="msg | filter('€')"></div> | ||
<div v-bind:id="msg | filterA | filterB"></div> | ||
</template> | ||
``` | ||
|
||
</eslint-code-block> | ||
|
||
### :wrench: Options | ||
|
||
Nothing. | ||
|
||
## :books: Further Reading | ||
|
||
- [Vue RFCs - Remove support for filters.](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0015-remove-filters.md) | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-filter.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-filter.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,43 @@ | ||
/** | ||
* @author Przemyslaw Falowski (@przemkow) | ||
* @fileoverview disallow using deprecated filters syntax | ||
*/ | ||
'use strict' | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
const utils = require('../utils') | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: 'disallow using deprecated filters syntax', | ||
category: undefined, | ||
url: 'https://eslint.vuejs.org/rules/no-deprecated-filter.html' | ||
}, | ||
fixable: null, | ||
schema: [], | ||
messages: { | ||
noDeprecatedFilter: 'Filters are deprecated.' | ||
} | ||
}, | ||
|
||
create: function (context) { | ||
return utils.defineTemplateBodyVisitor(context, { | ||
'VFilterSequenceExpression' (node) { | ||
context.report({ | ||
node, | ||
loc: node.loc, | ||
messageId: 'noDeprecatedFilter' | ||
}) | ||
} | ||
}) | ||
} | ||
} |
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,72 @@ | ||
/** | ||
* @author Przemyslaw Falowski (@przemkow) | ||
* @fileoverview disallow using deprecated filters syntax | ||
*/ | ||
'use strict' | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
const rule = require('../../../lib/rules/no-deprecated-filter') | ||
const RuleTester = require('eslint').RuleTester | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: require.resolve('vue-eslint-parser'), | ||
parserOptions: { ecmaVersion: 2015 } | ||
}) | ||
|
||
ruleTester.run('no-deprecated-filter', rule, { | ||
valid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: '<template>{{ msg }}</template>' | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template>{{ method(msg) }}</template>' | ||
} | ||
], | ||
|
||
invalid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: '<template>{{ msg | filter }}</template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template>{{ msg | filter(x) }}</template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template>{{ msg | filterA | filterB }}</template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div v-for="msg in messages">{{ msg | filter }}</div></template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div v-bind:id="msg | filter"></div></template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div v-bind:id="msg | filter(aaa)"></div></template>', | ||
errors: ['Filters are deprecated.'] | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div v-bind:id="msg | filterA | filterB"></div></template>', | ||
errors: ['Filters are deprecated.'] | ||
} | ||
] | ||
}) |