Skip to content

Commit 424bcc2

Browse files
authored
Add vue/no-deprecated-vue-config-keycodes rule (#1118)
1 parent 0849a27 commit 424bcc2

7 files changed

+149
-1
lines changed

docs/rules/README.md

Lines changed: 1 addition & 0 deletions
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-scope-attribute](./no-deprecated-slot-scope-attribute.md) | disallow deprecated `slot-scope` attribute (in Vue.js 2.6.0+) | :wrench: |
5050
| [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: |
5151
| [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: |
52+
| [vue/no-deprecated-vue-config-keycodes](./no-deprecated-vue-config-keycodes.md) | disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+) | |
5253
| [vue/no-dupe-keys](./no-dupe-keys.md) | disallow duplication of field names | |
5354
| [vue/no-duplicate-attributes](./no-duplicate-attributes.md) | disallow duplication of attributes | |
5455
| [vue/no-lifecycle-after-await](./no-lifecycle-after-await.md) | disallow asynchronously registered lifecycle hooks | |
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/no-deprecated-vue-config-keycodes
5+
description: disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+)
6+
---
7+
# vue/no-deprecated-vue-config-keycodes
8+
> disallow using deprecated `Vue.config.keyCodes` (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 `Vue.config.keyCodes` (in Vue.js 3.0.0+)
15+
16+
<eslint-code-block filename="a.js" language="javascript ":rules="{'vue/no-deprecated-vue-config-keycodes': ['error']}">
17+
18+
```js
19+
/* ✗ BAD */
20+
Vue.config.keyCodes = {
21+
// ...
22+
}
23+
```
24+
25+
</eslint-code-block>
26+
27+
## :wrench: Options
28+
29+
Nothing.
30+
31+
## :couple: Related rules
32+
33+
- [vue/no-deprecated-v-on-number-modifiers]
34+
- [API - Global Config - keyCodes]
35+
36+
[vue/no-deprecated-v-on-number-modifiers]: ./no-deprecated-v-on-number-modifiers.md
37+
[API - Global Config - keyCodes]: https://vuejs.org/v2/api/#keyCodes
38+
39+
## :books: Further reading
40+
41+
- [Vue RFCs - 0014-drop-keycode-support](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0014-drop-keycode-support.md)
42+
43+
## :mag: Implementation
44+
45+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/no-deprecated-vue-config-keycodes.js)
46+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/no-deprecated-vue-config-keycodes.js)

lib/configs/vue3-essential.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'vue/no-deprecated-slot-scope-attribute': 'error',
1818
'vue/no-deprecated-v-bind-sync': 'error',
1919
'vue/no-deprecated-v-on-number-modifiers': 'error',
20+
'vue/no-deprecated-vue-config-keycodes': 'error',
2021
'vue/no-dupe-keys': 'error',
2122
'vue/no-duplicate-attributes': 'error',
2223
'vue/no-lifecycle-after-await': 'error',

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = {
5050
'no-deprecated-slot-scope-attribute': require('./rules/no-deprecated-slot-scope-attribute'),
5151
'no-deprecated-v-bind-sync': require('./rules/no-deprecated-v-bind-sync'),
5252
'no-deprecated-v-on-number-modifiers': require('./rules/no-deprecated-v-on-number-modifiers'),
53+
'no-deprecated-vue-config-keycodes': require('./rules/no-deprecated-vue-config-keycodes'),
5354
'no-dupe-keys': require('./rules/no-dupe-keys'),
5455
'no-duplicate-attributes': require('./rules/no-duplicate-attributes'),
5556
'no-empty-pattern': require('./rules/no-empty-pattern'),
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @author Yosuke Ota
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
// ------------------------------------------------------------------------------
8+
// Rule Definition
9+
// ------------------------------------------------------------------------------
10+
11+
module.exports = {
12+
meta: {
13+
type: 'problem',
14+
docs: {
15+
description: 'disallow using deprecated `Vue.config.keyCodes` (in Vue.js 3.0.0+)',
16+
categories: ['vue3-essential'],
17+
url: 'https://eslint.vuejs.org/rules/no-deprecated-vue-config-keycodes.html'
18+
},
19+
fixable: null,
20+
schema: [],
21+
messages: {
22+
unexpected: '`Vue.config.keyCodes` are deprecated.'
23+
}
24+
},
25+
26+
create: function (context) {
27+
return {
28+
"MemberExpression[property.type='Identifier'][property.name='keyCodes']" (node) {
29+
const config = node.object
30+
if (config.type !== 'MemberExpression' ||
31+
config.property.type !== 'Identifier' ||
32+
config.property.name !== 'config' ||
33+
config.object.type !== 'Identifier' ||
34+
config.object.name !== 'Vue') {
35+
return
36+
}
37+
context.report({
38+
node,
39+
messageId: 'unexpected'
40+
})
41+
}
42+
}
43+
}
44+
}

tests/lib/rules/no-deprecated-html-element-is.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ruleTester = new RuleTester({
2020
parserOptions: { ecmaVersion: 2019 }
2121
})
2222

23-
ruleTester.run('no-deprecated-inline-template', rule, {
23+
ruleTester.run('no-deprecated-html-element-is', rule, {
2424
valid: [
2525
{
2626
filename: 'test.vue',
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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-vue-config-keycodes')
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-vue-config-keycodes', rule, {
24+
25+
valid: [
26+
{
27+
filename: 'test.js',
28+
code: `Vue.config.silent = true`
29+
},
30+
{
31+
filename: 'test.js',
32+
code: 'config.keyCodes = {}'
33+
},
34+
{
35+
filename: 'test.js',
36+
code: 'V.config.keyCodes = {}'
37+
}
38+
],
39+
40+
invalid: [
41+
{
42+
filename: 'test.js',
43+
code: 'Vue.config.keyCodes = {}',
44+
errors: [{
45+
message: '`Vue.config.keyCodes` are deprecated.',
46+
line: 1,
47+
column: 1,
48+
type: 'MemberExpression',
49+
// messageId: 'unexpected',
50+
endLine: 1,
51+
endColumn: 20
52+
}]
53+
}
54+
]
55+
})

0 commit comments

Comments
 (0)