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

Jest plugin doesn't resolve the "rootPath" correctly #240

Closed
rdrezner opened this issue Sep 15, 2023 · 2 comments
Closed

Jest plugin doesn't resolve the "rootPath" correctly #240

rdrezner opened this issue Sep 15, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@rdrezner
Copy link

Hello, thanks for creating and maintaining knip - I really like this tool.

When I scan my project, I'm getting some false positives and they're coming from the jest configuration. Files such as:
<rootDir>/some_file.ts are listed as unused. I have the rootDir property set to ./src in jest config file.

I took a closer look at the jest plugin configuration and I noticed that in this line https://github.com/webpro/knip/blob/59d437d7184bbe5374da00be60ea25993eb63c72/src/plugins/jest/index.ts#L90 the plugin replaces the <rootDir>/ string with the empty one. It seems to me that this is not correct for projects that have the rootDir property defined in the jest configuration (see: https://jestjs.io/docs/configuration#rootdir-string).

When I change this code line to:

const replaceRootDir = (name: string) =>
    name.includes('<rootDir>') ? join(cwd, name.replace(/^.*<rootDir>/, config.rootDir ?? '')) : name;

knip doesn't list those file as unused which is the expected behaviour.

@rdrezner rdrezner added the bug Something isn't working label Sep 15, 2023
@webpro webpro closed this as completed in 2f58848 Sep 18, 2023
@webpro
Copy link
Member

webpro commented Sep 18, 2023

🚀 This issue has been resolved in v2.25.0. See Release 2.25.0 for release notes.

@webpro
Copy link
Member

webpro commented Sep 18, 2023

Thanks for reporting this, @rdrezner!

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