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

💡 Knip should throw on an invalid config #966

Open
Zamiell opened this issue Mar 2, 2025 · 2 comments
Open

💡 Knip should throw on an invalid config #966

Zamiell opened this issue Mar 2, 2025 · 2 comments
Labels
feature request Feature request

Comments

@Zamiell
Copy link
Contributor

Zamiell commented Mar 2, 2025

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

@Zamiell Zamiell added the feature request Feature request label Mar 2, 2025
@webpro
Copy link
Member

webpro commented Mar 2, 2025

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.

@Zamiell
Copy link
Contributor Author

Zamiell commented Mar 2, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

2 participants