Skip to content

Commit a1da518

Browse files
authored
prefer-includes and prefer-array-index-of: Prevent crash on Vue files (#2645)
1 parent 83e33b4 commit a1da518

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

rules/shared/simple-array-search-rule.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ export default function simpleArraySearchRule({method, replacement}) {
8585

8686
const callbackScope = scopeManager.acquire(callback);
8787
if (
88+
// Can't use scopeManager in vue template
89+
// https://github.com/vuejs/vue-eslint-parser/issues/263
90+
!callbackScope
8891
// `parameter` is used somewhere else
89-
findVariable(callbackScope, parameter).references.some(({identifier}) => identifier !== parameterInBinaryExpression)
92+
|| findVariable(callbackScope, parameter).references.some(({identifier}) => identifier !== parameterInBinaryExpression)
9093
|| isFunctionSelfUsedInside(callback, callbackScope)
9194
) {
9295
return;

test/shared/simple-array-search-rule-tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import outdent from 'outdent';
2+
import {parsers} from '../utils/test.js';
23

34
function snapshotTests({method, replacement}) {
45
return {
@@ -80,6 +81,13 @@ function snapshotTests({method, replacement}) {
8081

8182
// Already valid case
8283
`foo.${replacement}(0)`,
84+
85+
// Can't use scopeManager in vue template
86+
// https://github.com/vuejs/vue-eslint-parser/issues/263
87+
{
88+
code: `<template><div v-if="values.${method}(x => x === 'foo')"></div></template>`,
89+
languageOptions: {parser: parsers.vue},
90+
},
8391
],
8492

8593
invalid: [

0 commit comments

Comments
 (0)