diff --git a/lib/rules/component-api-style.js b/lib/rules/component-api-style.js
index 4d4b9f52e..9ebf01d68 100644
--- a/lib/rules/component-api-style.js
+++ b/lib/rules/component-api-style.js
@@ -274,19 +274,18 @@ module.exports = {
if (!name) {
continue
}
- const propAllowed = apis.some(
- (api) => api.allow && api.options.has(name)
- )
- if (!propAllowed) {
+ const disallowApi =
+ !apis.some((api) => api.allow && api.options.has(name)) &&
+ apis.find((api) => !api.allow && api.options.has(name))
+
+ if (disallowApi) {
context.report({
node: prop.key,
messageId: isPreferScriptSetup(allows)
? 'disallowComponentOptionPreferScriptSetup'
: 'disallowComponentOption',
data: {
- disallowedApi: apis.filter(
- (api) => !api.allow && api.options.has(name)
- )[0].apiName,
+ disallowedApi: disallowApi.apiName,
optionPhrase: buildOptionPhrase(name),
allowedApis: buildAllowedPhrase(allows)
}
diff --git a/tests/lib/rules/component-api-style.js b/tests/lib/rules/component-api-style.js
index 8c119fda7..6d4257533 100644
--- a/tests/lib/rules/component-api-style.js
+++ b/tests/lib/rules/component-api-style.js
@@ -181,6 +181,35 @@ tester.run('component-api-style', rule, {
}
`
+ },
+ {
+ // https://github.com/vuejs/eslint-plugin-vue/issues/1720
+ filename: 'test.vue',
+ options: [['composition']],
+ code: `
+
+
+
+
+
+
+
+
+
+ `
}
],
invalid: [