webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
6.14k stars 140 forks source link

OS commands are seen as unresolved dependencies. #46

Closed ElPrudi closed 1 year ago

ElPrudi commented 1 year ago

knip version: 1.6.1

A little funny thing about running knip after using npm init -y is that it sees the generated script

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
}

as unresolved dependencies:

Unlisted or unresolved dependencies (2)
echo  package.json
exit  package.json

I have little idea about operating systems, but I think it will react the same way with other OS commands.

webpro commented 1 year ago

Yeah, this should be documented better.

The problem here is that Knip does not know what is an npm package and what is an OS binary. While for echo and exit this may sound obvious, it's hard to draw a line here. Currently only these binaries are ignored: https://github.com/webpro/knip/blob/main/src/constants.ts#L20

Perhaps I should just add exit and echo to the list, since these packages are 9 and 12 years old, respectively.

For now you could add ignoreBinaries: ["echo", "exit"] to the Knip config.

ElPrudi commented 1 year ago

I think it would be useful to add the most commonly used Linux, CMD and PowerShell commands as I think these are very commonly included in scripts across plattforms. And to point out on the README if they are OS commands. Links: https://kinsta.com/blog/linux-commands/ https://www.digitalcitizen.life/best-cmd-commands/ https://www.educba.com/powershell-commands/

It's not the end of the world, but it's important to have heard of it.

webpro commented 1 year ago

Thanks for your input! I've added a few binaries to the ignore list (1.7.0) and a small section in the readme.

ElPrudi commented 1 year ago

I am going to close this, as it now covers these os commands. Thank you for your blazingly fast response and keep up the good work!