Skip to content

Commit

Permalink
Fix crash in component-api-style rule (#1721)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Nov 18, 2021
1 parent 20eaee7 commit c931ae6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/rules/component-api-style.js
Expand Up @@ -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)
}
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/rules/component-api-style.js
Expand Up @@ -181,6 +181,35 @@ tester.run('component-api-style', rule, {
}
</script>
`
},
{
// https://github.com/vuejs/eslint-plugin-vue/issues/1720
filename: 'test.vue',
options: [['composition']],
code: `
<template>
<div id="app">
<header>
<Navigation />
</header>
<main class="container-fluid mb-4" role="main">
<RouterView />
</main>
</div>
</template>
<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import Navigation from '@/components/app/nav/Navigation.vue'
export default defineComponent({
name: 'App',
components: {
Navigation,
},
})
</script>`
}
],
invalid: [
Expand Down

0 comments on commit c931ae6

Please sign in to comment.