knip icon indicating copy to clipboard operation
knip copied to clipboard

💡 Pass in configuration as command-line argument

Open joshuahhh opened this issue 11 months ago • 3 comments

Suggest an idea for Knip

AFAICT, to pass options into Knip you need to make a configuration file. I just wanna run Knip via npx with "ignoreExportsUsedInFile" enabled, and it seems tedious to make a config file for this every time (and clean it up after using Knip).

Am I missing some technique? Or might this be a useful feature for others? (Thanks!)

joshuahhh avatar Mar 08 '25 21:03 joshuahhh

This has come up before (in #823, also #573) and tbh the goal still isn't to have parity between CLI arguments and configuration file. Yet where to draw the line?

This particular RFC for ignoreExportsUsedInFile could lead to confusion: it's not only boolean but also an object. How should that be set from the command-line? Other options can be set per workspace, which would also get unwieldy on the CLI.

webpro avatar Mar 09 '25 17:03 webpro

Thanks for finding those, they are certainly related!

I realize now I didn't state my preferred resolution, which isn't a "ignoreExportsUsedInFile"-specific CLI option, but a generic "--config-json" (or whatever) option where you could pass in a JSON string on the command line. I hope that would allow a lot of lightweight usage patterns in one fell swoop.

Any thoughts on that idea? If it doesn't appeal, no worries – it seems this isn't a common need.

joshuahhh avatar Mar 10 '25 06:03 joshuahhh

That's not a bad idea, but doesn't strike me as a common thing across tooling.

Just an idea: it isn't that many more characters to do something create some sort of script like this:

echo '{"ignoreExportsUsedInFile": true}' > knip.json && npx knip && rm knip.json

echo 'export { default } from ../shared.knip.ts' > knip.ts && npx knip && rm knip.ts

webpro avatar Mar 10 '25 06:03 webpro

Another option is something like knip -c ../knip.json (https://knip.dev/reference/cli#--config-file)

webpro avatar Apr 06 '25 06:04 webpro