Skip to content

Commit d78ec7d

Browse files
authored
Add vue/no-deprecated-v-on-native-modifier rule (#1130)
1 parent cee165c commit d78ec7d

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed

docs/rules/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Enforce all the rules in this category, as well as all higher priority rules, wi
4949
| [vue/no-deprecated-slot-attribute](./no-deprecated-slot-attribute.md) | disallow deprecated `slot` attribute (in Vue.js 2.6.0+) | :wrench: |
5050
| [vue/no-deprecated-slot-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
5151
| [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: |
52+
| [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+) | |
5253
| [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: |
5354
| [vue/no-deprecated-vue-config-keycodes](./no-deprecated-vue-config-keycodes.md) | disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+) | |
5455
| [vue/no-dupe-keys](./no-dupe-keys.md) | disallow duplication of field names | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-v-on-native-modifier
5+
description: disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+)
6+
---
7+
# vue/no-deprecated-v-on-native-modifier
8+
> disallow using deprecated `.native` modifiers (in Vue.js 3.0.0+)
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 use of deprecated `.native` modifier on `v-on` directive (in Vue.js 3.0.0+)
15+
16+
<eslint-code-block :rules="{'vue/no-deprecated-v-on-native-modifier': ['error']}">
17+
18+
```vue
19+
<template>
20+
<!-- ✓ GOOD -->
21+
<CoolInput v-on:keydown.enter="onKeydownEnter" />
22+
<CoolInput @keydown.enter="onKeydownEnter" />
23+
24+
<!-- ✗ BAD -->
25+
<CoolInput v-on:keydown.native="onKeydown" />
26+
<CoolInput @keydown.enter.native="onKeydownEnter" />
27+
</template>
28+
```
29+
30+
</eslint-code-block>
31+
32+
## :wrench: Options
33+
34+
Nothing.
35+
36+
## :couple: Related rules
37+
38+
- [valid-v-on]
39+
40+
[valid-v-on]: valid-v-on.md
41+
42+
## :books: Further reading
43+
44+
- [Vue RFCs - 0031-attr-fallthrough](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0031-attr-fallthrough.md)
45+
46+
## :mag: Implementation
47+
48+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-v-on-native-modifier.js)
49+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-v-on-native-modifier.js)

lib/configs/vue3-essential.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'vue/no-deprecated-slot-attribute': 'error',
1818
'vue/no-deprecated-slot-scope-attribute': 'error',
1919
'vue/no-deprecated-v-bind-sync': 'error',
20+
'vue/no-deprecated-v-on-native-modifier': 'error',
2021
'vue/no-deprecated-v-on-number-modifiers': 'error',
2122
'vue/no-deprecated-vue-config-keycodes': 'error',
2223
'vue/no-dupe-keys': 'error',

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
'no-deprecated-slot-attribute': require('./rules/no-deprecated-slot-attribute'),
5151
'no-deprecated-slot-scope-attribute': require('./rules/no-deprecated-slot-scope-attribute'),
5252
'no-deprecated-v-bind-sync': require('./rules/no-deprecated-v-bind-sync'),
53+
'no-deprecated-v-on-native-modifier': require('./rules/no-deprecated-v-on-native-modifier'),
5354
'no-deprecated-v-on-number-modifiers': require('./rules/no-deprecated-v-on-number-modifiers'),
5455
'no-deprecated-vue-config-keycodes': require('./rules/no-deprecated-vue-config-keycodes'),
5556
'no-dupe-keys': require('./rules/no-dupe-keys'),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 `.native` modifiers (in Vue.js 3.0.0+)',
22+
categories: ['vue3-essential'],
23+
url: 'https://eslint.vuejs.org/rules/no-deprecated-v-on-native-modifier.html'
24+
},
25+
fixable: null,
26+
schema: [],
27+
messages: {
28+
deprecated: "'.native' modifier on 'v-on' directive is deprecated."
29+
}
30+
},
31+
32+
create (context) {
33+
return utils.defineTemplateBodyVisitor(context, {
34+
"VAttribute[directive=true][key.name.name='on'] > VDirectiveKey > VIdentifier[name='native']" (node) {
35+
const key = node.parent
36+
if (!key.modifiers.includes(node)) return
37+
38+
context.report({
39+
node,
40+
messageId: 'deprecated'
41+
})
42+
}
43+
})
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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-v-on-native-modifier')
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: 2015 }
21+
})
22+
23+
ruleTester.run('no-deprecated-v-on-native-modifier', rule, {
24+
25+
valid: [
26+
{
27+
filename: 'test.vue',
28+
code: "<template><input v-on:keyup.enter='fire'></template>"
29+
},
30+
{
31+
filename: 'test.vue',
32+
code: "<template><input @keyup.enter='fire'></template>"
33+
},
34+
{
35+
filename: 'test.vue',
36+
code: "<template><input v-native:foo.native.foo.bar='fire'></template>"
37+
},
38+
{
39+
filename: 'test.vue',
40+
code: "<template><input @native.enter='fire'></template>"
41+
},
42+
{
43+
filename: 'test.vue',
44+
code: "<template><input :keydown.native='fire'></template>"
45+
}
46+
],
47+
48+
invalid: [
49+
{
50+
filename: 'test.vue',
51+
code: "<template><input v-on:keyup.native='fore'></template>",
52+
errors: [
53+
{
54+
line: 1,
55+
column: 29,
56+
messageId: 'deprecated',
57+
endLine: 1,
58+
endColumn: 35
59+
}
60+
]
61+
},
62+
{
63+
filename: 'test.vue',
64+
code: "<template><input v-on:keyup.foo.native.bar='fore'></template>",
65+
errors: [
66+
{
67+
line: 1,
68+
column: 33,
69+
messageId: 'deprecated',
70+
endLine: 1,
71+
endColumn: 39
72+
}
73+
]
74+
}
75+
]
76+
})

0 commit comments

Comments
 (0)