Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for recognizing Vue components in .md files #2576

Open
2 tasks done
salazarr-js opened this issue Oct 14, 2024 · 7 comments
Open
2 tasks done

Add support for recognizing Vue components in .md files #2576

salazarr-js opened this issue Oct 14, 2024 · 7 comments

Comments

@salazarr-js
Copy link

salazarr-js commented Oct 14, 2024

Not sure if this is in the scope of eslint-plugin-vue or is more a responsibility of vitepress itself, but there is no mention on the docs of how to lint .md files when you are using vitepress

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.12.0
  • eslint-plugin-vue version: ^9.28.0
  • Vue version: ^3.5.11
  • Vitepress: ^1.4.0
  • Node version: v20.17.0
  • Operating System: Microsoft Windows 11 Pro Version 10.0.22631 Build 22631

Please show your full configuration:

import js from '@eslint/js';
import ts from 'typescript-eslint';
import vue from 'eslint-plugin-vue'

/** @type {import('eslint').Linter.Config[]} */
export default [
  js.configs.recommended,
  ...ts.configs.recommended,
  ...vue.configs['flat/recommended'],
  {
    files: ['*.vue', '**/*.vue'],
    languageOptions: {
      parserOptions: {
        parser: '@typescript-eslint/parser'
      }
    }
  }
];

What did you do?

I use the custom parser config example, but the plugin ignores all the .md files, if I add the .md globs to the files config, the lint script throws an error Parsing error: Invalid character type of error

{
    files: ['*.vue', '**/*.vue', '*.md', '**/*.md'],
    extends: [
      ...vue.configs['flat/recommended'],
    ],
  },
  {
    files: ['*.vue', '**/*.vue', '*.md', '**/*.md'],
    languageOptions: {
      parserOptions: {
        parser: '@typescript-eslint/parser'
      }
    }
  },

Not sure if I could use and set a custom parser from @eslint/markdown or marked for this use case.
All the .ts and .vue files are correctly linted

What did you expect to happen?

The eslint-plugin-vue should be able to lint the vue components in .md files

What actually happened?

\vitepress-eslint\docs\components\linted.vue
  1:1  error  Component name "linted" should always be multi-word  vue/multi-word-component-names

\vitepress-eslint\docs\index.md
  1:0  error  Parsing error: Invalid character

\vitepress-eslint\docs\utils\linted.ts
  5:7   error  'lorem' is assigned a value but never used  @typescript-eslint/no-unused-vars
  5:14  error  Unexpected any. Specify a different type    @typescript-eslint/no-explicit-any

\vitepress-eslint\readme.md
  1:0  error  Parsing error: Invalid character

✖ 5 problems (5 errors, 0 warnings)

Repository to reproduce this issue

https://github.com/salazarr-js/vitepress-eslint

@FloEdelmann
Copy link
Member

This is indeed out of scope for eslint-plugin-vue. That the Vue parser chokes on Markdown files is expected.

However, you can indeed use @eslint/markdown's processor config, which creates virtual .js or .ts files for code blocks in Markdown files, which in turn can then be linted by eslint-plugin-vue.

@FloEdelmann FloEdelmann closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2024
@salazarr-js
Copy link
Author

salazarr-js commented Oct 15, 2024

@FloEdelmann thanks for your response, I understand that we can use the @eslint/markdown's processor to lint code blocks from .md files, but what about the script tag with vue logic like

# Vue script in `.md` files aren't linted

some markdown content

<LintedComponent />

```ts
console.warn(`code blocks can be linted`)
```

<script setup lang="ts">
  import { ref } from 'vue'
  import LintedComponent from './components/linted.vue'

  console.warn("Vue script in `.md` files aren't linted")
  const lorem = ref('ipsum')
</script>

@FloEdelmann
Copy link
Member

FloEdelmann commented Oct 15, 2024

But that is not md but mdx, right? Nevermind, it isn't.

@FloEdelmann
Copy link
Member

I've never heard about this use case. Is it supported/endorsed specifically by Vitepress, or do you know of other frameworks that allow/execute/transform <script> tags in Markdown files?

@salazarr-js
Copy link
Author

salazarr-js commented Oct 15, 2024

Vitepress brings the ability to use Vue component logic in .md files out of the box, vuepress did this before, and I found that SveltKit provides this feature too but through a preprocessor. For a moment I thought astro did the same, but I realized they use the .astro file extension

Vitepress - Using Vue in Markdown
Vuepress - Using Vue in Markdown
MDsveX - Markdown preprocessor for Svelte

⁉️ Not sure if you mean only vue frameworks or frameworks in general

@FloEdelmann
Copy link
Member

@ota-meshi Do you think this is worth supporting?

@salazarr-js
Copy link
Author

salazarr-js commented Oct 15, 2024

I am not sure if it's worth mentioning that vuejs/language-tools support .md files.

It would be great to have both IntelliSense and linting support for vitepress and vuepress projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants