plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.26k stars 44 forks source link

[vscode] the plugin reports `catch` but I'm using `ignoreCatch: true` #85

Open JounQin opened 3 years ago

JounQin commented 3 years ago

Version(if relevant): 2.16.3

Environment(if relevant):

Code(if relevant):

export const requirePkg = <T>(
  plugin: string,
  prefix: string,
  filePath?: string,
): T => {
  if (filePath && /^\.\.?([/\\]|$)/.test(plugin)) {
    plugin = path.resolve(path.dirname(filePath), plugin)
  }
  prefix = prefix.endsWith('-') ? prefix : prefix + '-'
  const packages = [
    plugin,
    plugin.startsWith('@')
      ? plugin.replace('/', '/' + prefix)
      : prefix + plugin,
  ]
  let error: Error
  for (const pkg of packages) {
    try {
      // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-return
      return require(pkg)
    } catch (err) {
      if (!error) {
        error = err
      }
    }
  }
  throw error
}

Expected:

No warning reported

Actual:

image


Besides, this cli works correctly.

plantain-00 commented 3 years ago

I can't reproduce this 屏幕快照 2021-03-01 14 32 51 屏幕快照 2021-03-01 14 32 41

JounQin commented 3 years ago

So the vscode plugin will not read type-coverage configuration from package.json? It doesn't make sense to me.

JounQin commented 3 years ago

Then I have an idea that we should provide an option which presents whether to enable this plugin's function, reading type-coverage configuration by default.

What means when no type-coverage configuration found, this plugin should be disabled.

plantain-00 commented 3 years ago

The CLI read package.json from process.cwd(), but the vscode plugin doesn't know where is your CLI process.cwd(). For example in a monorepo repository, you can run type-coverage in the root directory, or in a package directory, they have different package.json.

JounQin commented 3 years ago

A lot of tools like eslint, tslint, prettier, etc have similar situation but they are just working when they are enabled specifically.

We can find up package.json for type-coverage configuration from current file to top workpace folder. (Of course, cache is required for better performance)

plantain-00 commented 3 years ago

I checked what tslint does, default tslint.json and configured tslint.json is relative to the project root(tsconfig.json) rather than top workspace folder: https://github.com/Microsoft/typescript-tslint-plugin#configuration-options

JounQin commented 3 years ago

@plantain-00 I have this option enabled in vscode but still not working

image

image

plantain-00 commented 3 years ago

I can't reproduce it. 屏幕快照 2021-03-15 22 58 42 屏幕快照 2021-03-15 22 58 27

JounQin commented 3 years ago

That's weird then. I'm using a mono repo in workspace with multi projects.

Can you try https://github.com/mdx-js/eslint-mdx at https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-mdx/src/parser.ts#L225?

plantain-00 commented 3 years ago

Still can not reproduce it. The catch any is ignored and other any is reported. 屏幕快照 2021-03-16 21 32 33 屏幕快照 2021-03-16 21 33 01