diff --git a/docs/rules/README.md b/docs/rules/README.md index d022dd67f..a6f2627ea 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -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 | | diff --git a/docs/rules/no-deprecated-v-on-native-modifier.md b/docs/rules/no-deprecated-v-on-native-modifier.md new file mode 100644 index 000000000..93620cd7b --- /dev/null +++ b/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+) + + + +```vue + +``` + + + +## :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) diff --git a/lib/configs/vue3-essential.js b/lib/configs/vue3-essential.js index 651ff096b..93e4996ba 100644 --- a/lib/configs/vue3-essential.js +++ b/lib/configs/vue3-essential.js @@ -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', diff --git a/lib/index.js b/lib/index.js index fa2bc4347..9faa91636 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'), diff --git a/lib/rules/no-deprecated-v-on-native-modifier.js b/lib/rules/no-deprecated-v-on-native-modifier.js new file mode 100644 index 000000000..d93755436 --- /dev/null +++ b/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' + }) + } + }) + } +} diff --git a/tests/lib/rules/no-deprecated-v-on-native-modifier.js b/tests/lib/rules/no-deprecated-v-on-native-modifier.js new file mode 100644 index 000000000..772a56918 --- /dev/null +++ b/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: "" + }, + { + filename: 'test.vue', + code: "" + }, + { + filename: 'test.vue', + code: "" + }, + { + filename: 'test.vue', + code: "" + }, + { + filename: 'test.vue', + code: "" + } + ], + + invalid: [ + { + filename: 'test.vue', + code: "", + errors: [ + { + line: 1, + column: 29, + messageId: 'deprecated', + endLine: 1, + endColumn: 35 + } + ] + }, + { + filename: 'test.vue', + code: "", + errors: [ + { + line: 1, + column: 33, + messageId: 'deprecated', + endLine: 1, + endColumn: 39 + } + ] + } + ] +})