diff --git a/.changeset/wild-symbols-grow.md b/.changeset/wild-symbols-grow.md new file mode 100644 index 000000000..3100fae82 --- /dev/null +++ b/.changeset/wild-symbols-grow.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-vue': minor +--- + +[`vue/component-api-style`](https://eslint.vuejs.org/rules/component-api-style.html) now supports Vue 3.6+ Vapor mode style with the new `script-setup-vapor` option diff --git a/docs/rules/component-api-style.md b/docs/rules/component-api-style.md index 7a81176c9..0b9c926f5 100644 --- a/docs/rules/component-api-style.md +++ b/docs/rules/component-api-style.md @@ -14,7 +14,7 @@ since: v7.18.0 This rule aims to make the API style you use to define Vue components consistent in your project. -For example, if you want to allow only ` +``` + + + + + +```vue + + +``` + + + ### `["options"]` diff --git a/lib/rules/component-api-style.js b/lib/rules/component-api-style.js index 550eebfed..da825b2e8 100644 --- a/lib/rules/component-api-style.js +++ b/lib/rules/component-api-style.js @@ -7,13 +7,14 @@ const utils = require('../utils') /** - * @typedef { 'script-setup' | 'composition' | 'composition-vue2' | 'options' } PreferOption + * @typedef { 'script-setup' | 'script-setup-vapor' | 'composition' | 'composition-vue2' | 'options' } PreferOption * * @typedef {PreferOption[]} UserPreferOption * * @typedef {object} NormalizeOptions * @property {object} allowsSFC * @property {boolean} [allowsSFC.scriptSetup] + * @property {boolean} [allowsSFC.scriptSetupVapor] * @property {boolean} [allowsSFC.composition] * @property {boolean} [allowsSFC.compositionVue2] * @property {boolean} [allowsSFC.options] @@ -26,6 +27,7 @@ const utils = require('../utils') /** @type {PreferOption[]} */ const STYLE_OPTIONS = [ 'script-setup', + 'script-setup-vapor', 'composition', 'composition-vue2', 'options' @@ -48,6 +50,10 @@ function parseOptions(options) { opts.allowsSFC.scriptSetup = true break } + case 'script-setup-vapor': { + opts.allowsSFC.scriptSetupVapor = true + break + } case 'composition': { opts.allowsSFC.composition = true opts.allowsOther.composition = true @@ -143,6 +149,7 @@ const LIFECYCLE_HOOK_OPTIONS = new Set([ /** * @param {object} allowsOpt * @param {boolean} [allowsOpt.scriptSetup] + * @param {boolean} [allowsOpt.scriptSetupVapor] * @param {boolean} [allowsOpt.composition] * @param {boolean} [allowsOpt.compositionVue2] * @param {boolean} [allowsOpt.options] @@ -152,6 +159,9 @@ function buildAllowedPhrase(allowsOpt) { if (allowsOpt.scriptSetup) { phrases.push('` + `, + options: [['script-setup-vapor']] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [['script-setup', 'script-setup-vapor']] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [['script-setup', 'script-setup-vapor']] + }, { filename: 'test.js', code: ` @@ -845,6 +875,96 @@ tester.run('component-api-style', rule, { column: 9 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + options: [['script-setup-vapor']], + errors: [ + { + message: + '` + `, + options: [['script-setup']], + errors: [ + { + message: + '` + `, + options: [['script-setup-vapor']], + errors: [ + { + message: + 'Options API is not allowed in your project. Use ` + `, + options: [['script-setup-vapor', 'script-setup']], + errors: [ + { + message: + 'Options API is not allowed in your project. `data` option is part of the Options API. Use `