Skip to content

Knip says class members are unused but they are used #339

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

Closed
Zamiell opened this issue Nov 9, 2023 · 3 comments
Closed

Knip says class members are unused but they are used #339

Zamiell opened this issue Nov 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Zamiell
Copy link
Contributor

Zamiell commented Nov 9, 2023

This is on knip version 2.40.1.

Steps to reproduce:

git clone git@github.com:IsaacScript/isaacscript.git
cd isaacscript
git checkout aa5b9e68ca3ec147d0b87ec83da8bd8a536dcf61
yarn
npx knip

The final lines of the output are:

Unused exported class members (6)
$schema                              Config  packages/isaacscript-cli/src/classes/Config.ts
customTargetModDirectoryName         Config  packages/isaacscript-cli/src/classes/Config.ts
enableIsaacScriptWatcherAutoRestart  Config  packages/isaacscript-cli/src/classes/Config.ts
isaacScriptCommonDev                 Config  packages/isaacscript-cli/src/classes/Config.ts
modsDirectory                        Config  packages/isaacscript-cli/src/classes/Config.ts
saveSlot                             Config  packages/isaacscript-cli/src/classes/Config.ts

I think this is a bug, because these fields do appear to be being used. For example, let's consider "customTargetModDirectoryName". If we search for that string in VSCode, we see that it is being used in the getModTargetDirectoryName function in the utils.ts file. And if we look where that function is being used, we can very quickly work our way back to the "main.ts" file, which is explicitly listed in the "entry" field in the "knip.json" file.

Furthermore, there are other bugs contained in this output that do not have to do with class members, do you want me to open separate issues for those?

@Zamiell Zamiell added the bug Something isn't working label Nov 9, 2023
@Zamiell Zamiell changed the title Knip says class members are unused but they aren't Knip says class members are unused but they are used Nov 9, 2023
@webpro
Copy link
Member

webpro commented Nov 9, 2023

Thanks for creating the reproduction, very clear. I looked into this today, but unfortunately it seems not straightforward to fix.

When running with knip -W packages/isaacscript-cli --production --strict the class members are not reported as unused, so the functionality itself works fine. Yet with multiple workspaces somehow the moment it tries to find references to the class members, not all files are resolved cq part of the program (so it doesn't find references). Will need to dig deeper.

And yes, please file one issue per bug. This way, we can discuss and keep track of them separately. Some take more time than others. I can close them separately when finished.

@webpro webpro closed this as completed in 6ad4ced Nov 28, 2023
@webpro
Copy link
Member

webpro commented Nov 28, 2023

The issue was a duplicate package name, which Knip will now throw for.

@webpro
Copy link
Member

webpro commented Nov 28, 2023

🚀 This issue has been resolved in v3.1.0. See Release 3.1.0 for release notes.

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

2 participants