Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(RFC0015): add no-deprecated-filter rule #1043

Merged
merged 2 commits into from Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -160,6 +160,7 @@ For example:
| [vue/match-component-file-name](./match-component-file-name.md) | require component name property to match its file name | |
| [vue/max-len](./max-len.md) | enforce a maximum line length | |
| [vue/no-boolean-default](./no-boolean-default.md) | disallow boolean defaults | :wrench: |
| [vue/no-deprecated-filter](./no-deprecated-filter.md) | disallow using deprecated filters syntax | |
| [vue/no-deprecated-scope-attribute](./no-deprecated-scope-attribute.md) | disallow deprecated `scope` attribute (in Vue.js 2.5.0+) | :wrench: |
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
Expand Down
50 changes: 50 additions & 0 deletions docs/rules/no-deprecated-filter.md
@@ -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)
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'no-async-in-computed-properties': require('./rules/no-async-in-computed-properties'),
'no-boolean-default': require('./rules/no-boolean-default'),
'no-confusing-v-for-v-if': require('./rules/no-confusing-v-for-v-if'),
'no-deprecated-filter': require('./rules/no-deprecated-filter'),
'no-custom-modifiers-on-v-model': require('./rules/no-custom-modifiers-on-v-model'),
'no-deprecated-scope-attribute': require('./rules/no-deprecated-scope-attribute'),
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
Expand Down
43 changes: 43 additions & 0 deletions lib/rules/no-deprecated-filter.js
@@ -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'
})
}
})
}
}
72 changes: 72 additions & 0 deletions tests/lib/rules/no-deprecated-filter.js
@@ -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.']
}
]
})