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

False Positive for Namespace Import in Vue SFC with Script Setup #740

Closed
kirkbaly opened this issue Jul 26, 2024 · 12 comments
Closed

False Positive for Namespace Import in Vue SFC with Script Setup #740

kirkbaly opened this issue Jul 26, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@kirkbaly
Copy link

Reproduction url

https://stackblitz.com/edit/github-bquuj6

Description of the issue

Knip does not detect used exports that are used via namespace imports in Vue SFCs with script setup.

In this example, Bar.bar is reported as unused, while Baz.baz is reported as used. Of course, the same import and usage of Bar in a TS file would be reported as used.

<script setup lang="ts">
import * as Bar from 'Bar.ts';
import { baz } from 'Baz.ts';

Bar.bar();
baz();
</script>
@kirkbaly kirkbaly added the bug Something isn't working label Jul 26, 2024
@webpro
Copy link
Collaborator

webpro commented Jul 27, 2024

This is basically a dup of #733

Knip only extracts import statements in the built-in "compilers", you'd need to install an actual compiler.

And I need to document this properly :)

@kirkbaly
Copy link
Author

Ah, thanks for the info. I read through most of the docs but somehow missed that 🤦

Unfortunately, I forked the repro and made those changes (after fixing the missing declaration of getStyleImports and adding the css compiler), and it didn't have any effect. Here's that url: https://stackblitz.com/edit/github-bquuj6-32sfgs

Wouldn't be surprised if I'm doing something wrong, but I'm still new to Knip and not very familiar with the vue sfc compiler.

@webpro
Copy link
Collaborator

webpro commented Jul 28, 2024

What does the compiled JS look like? The return value is what we're interested in, because that's what Knip is working with.

@webpro
Copy link
Collaborator

webpro commented Oct 31, 2024

Closing due to inactivity.

@webpro webpro closed this as completed Oct 31, 2024
@yishuolin
Copy link
Contributor

The compiled output from @kirkbaly's example appears to be correct, as shown below

import * as Bar from 'Bar.ts';
import { baz } from 'Baz.ts';

Bar.bar();
baz();

After investigating, I suspect that this issue might be due to Knip only updating importedInternalSymbols for DEFAULT_EXTENSIONS here?

@webpro
Copy link
Collaborator

webpro commented Nov 14, 2024

@yishuolin Thanks, so you're having the same issue? That could very well be the cause indeed. Would you like submit a pull request? No worries if not and I'll investigate/pick it up later.

@yishuolin
Copy link
Contributor

@webpro I encountered a similar issue—Knip reports unused enumMembers if the enum member is used in a file compiled by a custom compiler. Here's a minimal reproduction.

Apologies, but I might not be able to look into this issue at the moment, so I’ll need to hand it over to you. Thank you!

@webpro
Copy link
Collaborator

webpro commented Nov 14, 2024

@yishuolin @kirkbaly I might have a fix, would be great if you could test this version in your project(s):

npm i -D https://pkg.pr.new/knip@249794a

@webpro webpro reopened this Nov 14, 2024
@yishuolin
Copy link
Contributor

Thanks for the fix! I tested it, and it worked perfectly in my project.

@webpro
Copy link
Collaborator

webpro commented Nov 15, 2024

Thank you so much for confirming. I'll release it today.

@webpro webpro closed this as completed in 8d53df5 Nov 15, 2024
@webpro
Copy link
Collaborator

webpro commented Nov 15, 2024

🚀 This issue has been resolved in v5.37.1. See Release 5.37.1 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

@kirkbaly
Copy link
Author

Awesome! Sorry for the unresponsiveness, but thanks for the fix! Now to scan the template as well as the script... 😅 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants