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
7.06k stars 177 forks source link

💡 Provide configuration helper functions for JS/TS usage #843

Open ben-eb opened 5 days ago

ben-eb commented 5 days ago

Suggest an idea for this project

Hello 👋

Firstly thanks for your work on this project, it's been super useful and has helped a lot with some recent refactoring work I've done. 🎉

One thing I noticed with the configuration is that it can be a little difficult to scan with the magic ! suffix used for denoting a production entry file. So I found myself writing a couple of helper functions:

import type { KnipConfig } from 'knip';

const config: KnipConfig = {
    entry: [
        production('services/**/index.ts'),
        development('services/**/integration.ts'),
    ],
};

export default config;

function production(file: string): string {
    return `${file}!`;
}

function development(file: string): string {
    return file;
}

Even though these functions are not so complex I find that the "tag" applied to the string makes the configuration much more self-documenting. A new developer to the project will most likely wonder what ! means at the end of a file glob and spend some time looking for this in the documentation.

I was wondering if you would be amenable to adding these helpers to the project itself? Perhaps a not function could work for a leading ! too, though I think !path/to/files/*.ts is much more of a standard pattern these days. 🙂

Thanks!

webpro commented 1 hour ago

Thanks @ben-eb! To be honest I'm not really in favor of adding this. Since Knip offers a way to author configuration in TypeScript and as you point out such functions are not so complex to write. Now you can name and use them however you prefer.