vuejs/eslint-plugin-vue

`indexOf` combined with the `not equal to` operator Exception

Closed this issue · 5 comments

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • ESLint version: 9.23.0
  • eslint-plugin-vue version: 10.0.0
  • Vue version: 3.3.13
  • Node version: 22.11.0
  • Operating System:

Please show your full configuration:

import antfu from "@antfu/eslint-config";

export default antfu(
  {
    vue: {
      overrides: {
        "vue/custom-event-name-casing": ["error", "kebab-case"],
      },
    },

    formatters: {
      markdown: "Prettier",
    },

    ignores: [
      "**/*.md",
      "docs/",
      "**/*.test.*",
      "**/*.d.ts",
    ],

    stylistic: {
      semi: true,
      quotes: "double",

    },

    rules: {
      "ts/no-unsafe-function-type": "off",
      "ts/prefer-literal-enum-member": "off"
    },
  },
);

What did you do?

<script setup lang="ts">

console.log([].indexOf(1) != -1);   
</script>

<template>
  <div></div>
</template>

What did you expect to happen?
In a normal js file, it will be linted as console.log([].includes(1));

What actually happened?

Repository to reproduce this issue

The vscode ide will freeze for a while, and then the final vue file will be linted as the following code

<script setup lang="ts">
console.log([].indexOf(1) != -1);   
</script>

<template>
  <div></div>
</template>.includes(1));
</script>

<template>
  <div/>
</template>.includes(1));
</script>

...

Please note The above code will generate more than 5000 lines repeatedly in the vue file.

<template>
  <div/>
</template>.includes(1));
</script>

Please provide a reproduction using Stackblitz or a GitHub repository.

@waynzh
hi! repo The above is the repository address. After you clone the repository, run pnpm install and then save the file in 1.vue

I just tried to create this example from Stackblitz, but it didn't reproduce the problem. However, it reproduces in vscode.

@waynzh hi! repo The above is the repository address. After you clone the repository, run pnpm install and then save the file in 1.vuehi! repo 以上是仓库地址。克隆仓库后,运行 pnpm install ,然后保存文件到 1.vue

@waynzh run pnpm lint:eslint It is also reproducible

The specific rule causing the error is unicorn/prefer-includes, I'll close it to keep track there.

It seems there’s a related issue reported here: sindresorhus/eslint-plugin-unicorn#2643. You could consider opening an issue with them.