From 7796cb5dda0b99a5a558ab637b03738f702bef8c Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Thu, 11 Nov 2021 00:49:33 +0100 Subject: [PATCH 1/3] Add `composition-vue2` api style --- docs/rules/component-api-style.md | 7 +- lib/rules/component-api-style.js | 84 ++++++--- tests/lib/rules/component-api-style.js | 247 +++++++++++++++++++++++++ 3 files changed, 312 insertions(+), 26 deletions(-) diff --git a/docs/rules/component-api-style.md b/docs/rules/component-api-style.md index d20dc9fe3..af29316e3 100644 --- a/docs/rules/component-api-style.md +++ b/docs/rules/component-api-style.md @@ -73,14 +73,15 @@ export default { ```json { "vue/component-api-style": ["error", - ["script-setup", "composition"] // "script-setup", "composition", or "options" + ["script-setup", "composition"] // "script-setup", "composition", "composition-vue2", or "options" ] } ``` - Array options ... Defines the API styles you want to allow. Default is `["script-setup", "composition"]`. You can use the following values. - - `"script-setup"` ... If set, allows ` ` + }, + { + filename: 'test.vue', + options: [['composition-vue2']], + code: ` + + ` } ], invalid: [ @@ -561,6 +583,231 @@ tester.run('component-api-style', rule, { column: 9 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [['composition-vue2']], + errors: [ + { + message: + '` + `, + errors: [ + { + message: + 'Options API is not allowed in your project. `data` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 4, + column: 9 + } + ] + }, + { + filename: 'test.vue', + options: [['composition-vue2']], + code: ` + + `, + errors: [ + { + message: + 'Options API is not allowed in your project. `mixins` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 4, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `extends` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 5, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `data` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 7, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `computed` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 8, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `methods` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 9, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `watch` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 10, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `provide` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 11, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `inject` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 12, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `beforeCreate` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 14, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `created` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 15, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `beforeMount` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 16, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `mounted` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 17, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `beforeUpdate` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 18, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `updated` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 19, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `activated` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 20, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `deactivated` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 21, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `beforeDestroy` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 22, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `beforeUnmount` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 23, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `destroyed` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 24, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `unmounted` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 25, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `renderTracked` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 27, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `renderTriggered` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 28, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `errorCaptured` lifecycle hook is the API of Options API. Use Composition API (Vue 2) instead.', + line: 29, + column: 9 + }, + { + message: + 'Options API is not allowed in your project. `expose` option is the API of Options API. Use Composition API (Vue 2) instead.', + line: 31, + column: 9 + } + ] } ] }) From e02e3bb281ee25d7cbf9f03c77538bf12d8fe9af Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Thu, 11 Nov 2021 00:51:24 +0100 Subject: [PATCH 2/3] Improve error message --- lib/rules/component-api-style.js | 2 +- tests/lib/rules/component-api-style.js | 110 ++++++++++++------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/lib/rules/component-api-style.js b/lib/rules/component-api-style.js index 54928e066..af48d175f 100644 --- a/lib/rules/component-api-style.js +++ b/lib/rules/component-api-style.js @@ -206,7 +206,7 @@ module.exports = { disallowScriptSetup: '`