From c931ae69e6b257722719c283676fb2eb8ee57b68 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Thu, 18 Nov 2021 19:06:37 +0900 Subject: [PATCH] Fix crash in `component-api-style` rule (#1721) --- lib/rules/component-api-style.js | 13 ++++++------ tests/lib/rules/component-api-style.js | 29 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) 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: [