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

Question: does it support checking .vue file ? #66

Open
fleksin opened this issue Oct 10, 2020 · 5 comments
Open

Question: does it support checking .vue file ? #66

fleksin opened this issue Oct 10, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fleksin
Copy link

fleksin commented Oct 10, 2020

As the title suggests.
It seems like it doesn't support as I tested it.
Do we have plan adding this feature? if not, I'm considering making a PR

@plantain-00 plantain-00 added enhancement New feature or request help wanted Extra attention is needed labels Oct 10, 2020
@plantain-00
Copy link
Owner

PR is welcome.

@darrenmothersele
Copy link

I could have a go at this. Any clues on where to start adding support for *.vue files?

@plantain-00
Copy link
Owner

@darrenmothersele Some ideas:

  1. Design a way to find .vue files.
  2. Read the .vue files and parse typescript code from them(maybe by @vue/compiler-dom).
  3. Add the typescript source code to the program or create a new Program instance: https://github.com/plantain-00/type-coverage/blob/master/packages/core/src/core.ts#L27
  4. Check them and sum them up: https://github.com/plantain-00/type-coverage/blob/master/packages/core/src/core.ts#L133

@JounQin
Copy link
Contributor

JounQin commented Jun 25, 2021

vue-tsc may help.

@tomardern
Copy link

tomardern commented Mar 16, 2022

I've done a bit of digging this evening, here is what I've found.

Route 1 - using vue-tsc

vue-tsc has a method named createProgramProxy (https://github.com/johnsoncodehk/volar/blob/master/packages/vue-tsc/src/proxy.ts#L7), which could be used instead of ts.createProgram (https://github.com/plantain-00/type-coverage/blob/master/packages/core/src/core.ts#L27)

Something along the lines of:

import { createProgramProxy } from "vue-tsc/out/proxy.js";
//...
export async function lint(project: string, options?: Partial<LintOptions>) {
//...
// If Vue project use createProgramProxy, otherwise, use ts.createProgram
const program = createProgramProxy(
      {
        rootNames: rootNames,
        options: compilerOptions,
        host: undefined, // Language host??
        oldProgram: lintOptions.oldProgram,
      },
      compilerOptions,
      undefined,  // Language host??
      lintOptions.oldProgram
    );
// ...
 }

However, the createProgramProxy from vue-tsc requires passing through a compiler (https://github.com/johnsoncodehk/volar/blob/master/packages/vue-tsc/src/proxy.ts#L28), in which this package is passing undefined. a "compilerHost" is created deep within the typescript core repo, which seems like quite a big undertaking.... (https://github.com/microsoft/TypeScript/blob/d1fa945261a30616c5e3557d1a9fc18f3482af30/src/services/services.ts#L1397)

The volar package is currently undergoing a big refactor - https://github.com/johnsoncodehk/volar/pull/1050/files - so it might be worth looking at this once the refractor is out.

Route 2 - Learnings from vue-type-audit
Taking a look at a similar npm package (https://github.com/andoshin11/vue-type-audit), it looks like the "compilerHost" could be something similar to this:
https://github.com/andoshin11/vue-type-audit/blob/master/src/languageService/createHost.ts#L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants