💡 Pass in configuration as command-line argument
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!)
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.
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.
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
Another option is something like knip -c ../knip.json (https://knip.dev/reference/cli#--config-file)