💡 Knip should throw on an invalid config
Suggest an idea for Knip
Introduction
Consider the following config:
export default {
ignoreFiles: [ "eslint.config.mjs" ],
};
This config is subtly bugged because "ignoreFiles" should really be called "ignore". However, instead of sensibly throwing an error with something along the lines of Error: The "ignoreFiles" configuration field is unknown., Knip will instead silently ignore it and then charge ahead as per normal, complaining about "eslint.config.mjs" being unused.
Recommendation
One possible solution here is to show bugged config entries as "hints", and that would have the advantage of not breaking lint runs for users who have existing bugged/invalid configs.
However, I would strongly recommend to throw a hard error instead of a hint, as hints can be hidden from people for a really long time. Related issue: #891
Knip provides a JSON(C) Schema and TypeScript definitions to help with configuration. So that would be a good idea to start out with.
Knip uses Zod to throws error on certain types of misconfiguration. To be honest, I'm a little bit surprised it doesn't throw on the example given.
Yeah, so it sounds like the ".strict()" option needs to be added to the Zod schema: https://stackoverflow.com/questions/70415330/do-not-allow-extra-properties-with-zod-parse
:rocket: This issue has been resolved in v5.48.0. See Release 5.48.0 for release notes.
Using Knip in a commercial project? Please consider becoming a sponsor.