vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 667 forks source link

How does the flat configuration of eslint-plugin-vue only apply to vue files #2603

Open lvzhenbo opened 2 weeks ago

lvzhenbo commented 2 weeks ago

Checklist

Tell us about your environment

Please show your full configuration:

import { defineFlatConfig } from 'eslint-define-config';
import js from '@eslint/js';
import pluginVue from 'eslint-plugin-vue';
import vueTsEslintConfig from '@vue/eslint-config-typescript';
import prettierConfig from '@vue/eslint-config-prettier';
import parserVue from 'vue-eslint-parser';
import AutoImport from './.eslintrc-auto-import.json' with { type: 'json' };
import markdown from '@eslint/markdown';

export default defineFlatConfig([
  ...pluginVue.configs['flat/recommended'],
  js.configs.recommended,
  ...vueTsEslintConfig({
    supportedScriptLangs: {
      ts: true,
      tsx: true,
    },
  }),
  {
    name: 'app/vue-files',
    files: ['**/*.vue'],
    languageOptions: {
      parser: parserVue,
      parserOptions: {
        ecmaVersion: 'latest',
      },
    },
  },
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
    languageOptions: {
      globals: {
        ...AutoImport.globals,
      },
    },
    rules: {
      // 允许被禁止的类型 https://typescript-eslint.io/rules/ban-types/
      '@typescript-eslint/ban-types': 'off',
      // 允许any类型 https://typescript-eslint.io/rules/no-explicit-any/
      '@typescript-eslint/no-explicit-any': 'off',
      // 允许任何TS指令注释 https://typescript-eslint.io/rules/ban-ts-comment
      '@typescript-eslint/ban-ts-comment': 'off',
      // 允许空函数 https://typescript-eslint.io/rules/no-empty-function/
      '@typescript-eslint/no-empty-function': 'off',
      // 关闭强制多词组件名 https://eslint.vuejs.org/rules/multi-word-component-names.html
      'vue/multi-word-component-names': 'off',
      // 强制执行自我关闭风格 https://eslint.vuejs.org/rules/html-self-closing.html
      'vue/html-self-closing': [
        'error',
        {
          html: {
            void: 'always',
            normal: 'never',
            component: 'always',
          },
          svg: 'always',
          math: 'always',
        },
      ],
    },
  },
  {
    name: 'app/files-to-ignore',
    ignores: ['**/dist/**', '**/dist-ssr/**', '**/coverage/**'],
  },
  prettierConfig,
  {
    name: 'app/markdown-files',
    files: ['**/*.md'],
    plugins: {
      markdown,
    },
    language: 'markdown/commonmark',
    rules: {
      'markdown/no-html': 'error',
    },
  },
]);

What did you do?

I am planning to use the @ eslint/markdown package to solve the formatting problem of MD files

What did you expect to happen? ESLint should be running normally

What actually happened?

[Error - 13:31:37] An unexpected error occurred:
[Error - 13:31:37] TypeError: Error while loading rule 'vue/multi-word-component-names': Cannot read properties of undefined (reading 'getDocumentFragment')
Occurred while linting C:\Users\htk\Desktop\localStorage-manager\README.md
    at getScriptSetupElement (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint-plugin-vue@9.30.0_eslint@9.14.0_jiti@1.21.6_\node_modules\eslint-plugin-vue\lib\utils\index.js:2702:31)
    at Object.isScriptSetup (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint-plugin-vue@9.30.0_eslint@9.14.0_jiti@1.21.6_\node_modules\eslint-plugin-vue\lib\utils\index.js:2692:18)
    at Object.create (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint-plugin-vue@9.30.0_eslint@9.14.0_jiti@1.21.6_\node_modules\eslint-plugin-vue\lib\rules\multi-word-component-names.js:55:24)
    at createRuleListeners (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:943:21)
    at C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:1068:84
    at Array.forEach (<anonymous>)
    at runRules (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:999:34)
    at #flatVerifyWithoutProcessors (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:1911:31)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:1992:49)
    at Linter._verifyWithFlatConfigArray (C:\Users\htk\Desktop\localStorage-manager\node_modules\.pnpm\eslint@9.14.0_jiti@1.21.6\node_modules\eslint\lib\linter\linter.js:2081:21)

Repository to reproduce this issue

https://github.com/lvzhenbo/localStorage-manager