eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Crash in `unicorn/no-instanceof-builtins` and similar rules when linting .vue files
After upgrading from [email protected] to 57.0.0+ I'm experiencing ESLint crashes when linting .vue files with the following error:
Stack Trace
ESLint: 9.26.0
TypeError: Cannot read properties of null (reading 'childScopes')
Occurred while linting ./src/App.vue:14
Rule: "unicorn/explicit-length-check"
at getInnermostScope (file://./.yarn/__virtual__/@eslint-community-eslint-utils-virtual-d459a613f3/3/.yarn/berry/cache/@eslint-community-eslint-utils-npm-4.7.0-47503bfa2a-10c0.zip/node_modules/@eslint-community/eslint-utils/index.mjs:19:40)
at findVariable (file://./.yarn/__virtual__/@eslint-community-eslint-utils-virtual-d459a613f3/3/.yarn/berry/cache/@eslint-community-eslint-utils-npm-4.7.0-47503bfa2a-10c0.zip/node_modules/@eslint-community/eslint-utils/index.mjs:54:17)
at file://./.yarn/__virtual__/eslint-plugin-unicorn-virtual-c66979b7c0/3/.yarn/berry/cache/eslint-plugin-unicorn-npm-59.0.1-5373ae1135-10c0.zip/node_modules/eslint-plugin-unicorn/rules/shared/simple-array-search-rule.js:90:5
at EventEmitter.<anonymous> (file://./.yarn/__virtual__/eslint-plugin-unicorn-virtual-c66979b7c0/3/.yarn/berry/cache/eslint-plugin-unicorn-npm-59.0.1-5373ae1135-10c0.zip/node_modules/eslint-plugin-unicorn/rules/utils/rule.js:118:31)
at EventEmitter.emit (node:events:530:35)
at NodeEventGenerator.applySelector (./.yarn/__virtual__/vue-eslint-parser-virtual-7266f75b02/3/.yarn/berry/cache/vue-eslint-parser-npm-10.1.3-d7a30e8e7b-10c0.zip/node_modules/vue-eslint-parser/index.js:4373:26)
at NodeEventGenerator.applySelectors (./.yarn/__virtual__/vue-eslint-parser-virtual-7266f75b02/3/.yarn/berry/cache/vue-eslint-parser-npm-10.1.3-d7a30e8e7b-10c0.zip/node_modules/vue-eslint-parser/index.js:4393:22)
at NodeEventGenerator.enterNode (./.yarn/__virtual__/vue-eslint-parser-virtual-7266f75b02/3/.yarn/berry/cache/vue-eslint-parser-npm-10.1.3-d7a30e8e7b-10c0.zip/node_modules/vue-eslint-parser/index.js:4401:14)
at traverse (./.yarn/__virtual__/vue-eslint-parser-virtual-7266f75b02/3/.yarn/berry/cache/vue-eslint-parser-npm-10.1.3-d7a30e8e7b-10c0.zip/node_modules/vue-eslint-parser/index.js:169:13)
at traverse (./.yarn/__virtual__/vue-eslint-parser-virtual-7266f75b02/3/.yarn/berry/cache/vue-eslint-parser-npm-10.1.3-d7a30e8e7b-10c0.zip/node_modules/vue-eslint-parser/index.js:181:13)
At least the following rules are affected:
- unicorn/no-instanceof-builtins
- unicorn/number-literal-case
- unicorn/prefer-array-some
- unicorn/prefer-includes
Minimal package.json to reproduce:
{
"name": "test_eslint",
"packageManager": "[email protected]",
"devDependencies": {
"eslint": "^9.26.0",
"eslint-plugin-unicorn": "^59.0.0",
"eslint-plugin-vue": "^10.1.0",
"vue-eslint-parser": "^10.1.3"
}
}
and eslint.config.mjs
import unicorn from "eslint-plugin-unicorn";
import vue from "eslint-plugin-vue";
export default [
unicorn.configs["flat/recommended"],
...vue.configs["flat/recommended"],
{
files: ["**/*.vue"],
rules: {
// skipping the following rules fixes the issue
// "unicorn/no-instanceof-builtins": "off",
// "unicorn/number-literal-case": "off",
// "unicorn/prefer-array-some": "off",
// "unicorn/prefer-includes": "off"
}
}
];
I'm able to work around the issue by disabling the above rules for *.vue files, but I'd like to keep them enabled to ensure consistent linting behavior across all files, including Vue SFCs.
Looks like something wrong in @eslint-community/eslint-utils, can you share your App.vue file?
Looks like something wrong in
@eslint-community/eslint-utils, can you share yourApp.vuefile?
Sure.
<template>
<div v-for="item in items" :key="item.key">
<Item
:activated="selected.some(s => item.key === s)"
/>
</div>
</template>
<script setup>
import { ref } from "vue";
import Item from "./item.vue";
const items = ref([]);
const selected = ref([]);
</script>
If I remove the
:activated="selected.some(s => source.key === s)" line ESLint works, otherwise - it crushes
I'll take a look later. Thanks for the information.
Experienced the same, here's a sample of my template for additonal information.
@polis89 Would you mind upgrade to lastest version and try to enable these rules to check if they work with Vue files?
@fisker I can confirm that the latest version fixed the issue. Thank you so much