Skip to content

Commit

Permalink
Add vue/no-deprecated-v-on-native-modifier rule (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 16, 2020
1 parent cee165c commit d78ec7d
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/README.md
Expand Up @@ -49,6 +49,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
| [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: |
| [vue/no-deprecated-v-bind-sync](./no-deprecated-v-bind-sync.md) | disallow use of deprecated `.sync` modifier on `v-bind` directive (in Vue.js 3.0.0+) | :wrench: |
| [vue/no-deprecated-v-on-native-modifier](./no-deprecated-v-on-native-modifier.md) | disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+) | |
| [vue/no-deprecated-v-on-number-modifiers](./no-deprecated-v-on-number-modifiers.md) | disallow using deprecated number (keycode) modifiers (in Vue.js 3.0.0+) | :wrench: |
| [vue/no-deprecated-vue-config-keycodes](./no-deprecated-vue-config-keycodes.md) | disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+) | |
| [vue/no-dupe-keys](./no-dupe-keys.md) | disallow duplication of field names | |
Expand Down
49 changes: 49 additions & 0 deletions docs/rules/no-deprecated-v-on-native-modifier.md
@@ -0,0 +1,49 @@
---
pageClass: rule-details
sidebarDepth: 0
title: vue/no-deprecated-v-on-native-modifier
description: disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+)
---
# vue/no-deprecated-v-on-native-modifier
> disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+)
- :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 use of deprecated `.native` modifier on `v-on` directive (in Vue.js 3.0.0+)

<eslint-code-block :rules="{'vue/no-deprecated-v-on-native-modifier': ['error']}">

```vue
<template>
<!-- ✓ GOOD -->
<CoolInput v-on:keydown.enter="onKeydownEnter" />
<CoolInput @keydown.enter="onKeydownEnter" />
<!-- ✗ BAD -->
<CoolInput v-on:keydown.native="onKeydown" />
<CoolInput @keydown.enter.native="onKeydownEnter" />
</template>
```

</eslint-code-block>

## :wrench: Options

Nothing.

## :couple: Related rules

- [valid-v-on]

[valid-v-on]: valid-v-on.md

## :books: Further reading

- [Vue RFCs - 0031-attr-fallthrough](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0031-attr-fallthrough.md)

## :mag: Implementation

- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-v-on-native-modifier.js)
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-v-on-native-modifier.js)
1 change: 1 addition & 0 deletions lib/configs/vue3-essential.js
Expand Up @@ -17,6 +17,7 @@ module.exports = {
'vue/no-deprecated-slot-attribute': 'error',
'vue/no-deprecated-slot-scope-attribute': 'error',
'vue/no-deprecated-v-bind-sync': 'error',
'vue/no-deprecated-v-on-native-modifier': 'error',
'vue/no-deprecated-v-on-number-modifiers': 'error',
'vue/no-deprecated-vue-config-keycodes': 'error',
'vue/no-dupe-keys': 'error',
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Expand Up @@ -50,6 +50,7 @@ module.exports = {
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
'no-deprecated-slot-scope-attribute': require('./rules/no-deprecated-slot-scope-attribute'),
'no-deprecated-v-bind-sync': require('./rules/no-deprecated-v-bind-sync'),
'no-deprecated-v-on-native-modifier': require('./rules/no-deprecated-v-on-native-modifier'),
'no-deprecated-v-on-number-modifiers': require('./rules/no-deprecated-v-on-number-modifiers'),
'no-deprecated-vue-config-keycodes': require('./rules/no-deprecated-vue-config-keycodes'),
'no-dupe-keys': require('./rules/no-dupe-keys'),
Expand Down
45 changes: 45 additions & 0 deletions lib/rules/no-deprecated-v-on-native-modifier.js
@@ -0,0 +1,45 @@
/**
* @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 `.native` modifiers (in Vue.js 3.0.0+)',
categories: ['vue3-essential'],
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-on-native-modifier.html'
},
fixable: null,
schema: [],
messages: {
deprecated: "'.native' modifier on 'v-on' directive is deprecated."
}
},

create (context) {
return utils.defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name.name='on'] > VDirectiveKey > VIdentifier[name='native']" (node) {
const key = node.parent
if (!key.modifiers.includes(node)) return

context.report({
node,
messageId: 'deprecated'
})
}
})
}
}
76 changes: 76 additions & 0 deletions tests/lib/rules/no-deprecated-v-on-native-modifier.js
@@ -0,0 +1,76 @@
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-deprecated-v-on-native-modifier')
const RuleTester = require('eslint').RuleTester

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({
parser: require.resolve('vue-eslint-parser'),
parserOptions: { ecmaVersion: 2015 }
})

ruleTester.run('no-deprecated-v-on-native-modifier', rule, {

valid: [
{
filename: 'test.vue',
code: "<template><input v-on:keyup.enter='fire'></template>"
},
{
filename: 'test.vue',
code: "<template><input @keyup.enter='fire'></template>"
},
{
filename: 'test.vue',
code: "<template><input v-native:foo.native.foo.bar='fire'></template>"
},
{
filename: 'test.vue',
code: "<template><input @native.enter='fire'></template>"
},
{
filename: 'test.vue',
code: "<template><input :keydown.native='fire'></template>"
}
],

invalid: [
{
filename: 'test.vue',
code: "<template><input v-on:keyup.native='fore'></template>",
errors: [
{
line: 1,
column: 29,
messageId: 'deprecated',
endLine: 1,
endColumn: 35
}
]
},
{
filename: 'test.vue',
code: "<template><input v-on:keyup.foo.native.bar='fore'></template>",
errors: [
{
line: 1,
column: 33,
messageId: 'deprecated',
endLine: 1,
endColumn: 39
}
]
}
]
})

0 comments on commit d78ec7d

Please sign in to comment.