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
6.46k stars 150 forks source link

Get an issue count, when issues > 0 #736

Closed a-c-m closed 2 weeks ago

a-c-m commented 1 month ago

Currently, Kip reports a count per grouping (e.g. Duplicate exports) but does not give a total issue count at the end, but uses that total count against --max-issues to decide if it's going to exit 1.

This would be very useful in cases (like ours) where we've not got to 0 yet, but want to get there, so are setting --max-issues=XX and then deprecating it when we make improvements. Seeing what that new number is, would really help.

It could be in the form of an error (not just exit code) at the end "Knip found 123 issues" (in red if its more than max-issue, or green if under).

Ironically, a --min-issues would also help here, to allow us to fail the build (and update the build script) when enough progress has been made. But that's much less of a need.

Thanks!

webpro commented 1 month ago

You could create a basic custom reporter to suit your needs:

export default function({ counters, issues }) {
  // accumulate counters and print it
}

And then use it like so:

knip --reporter ./my-reporter.ts

Also see https://knip.dev/features/reporters#custom-reporters

a-c-m commented 1 month ago

True, may end up doing that - but I would say it should be default behaviour of the built-in reporters.

webpro commented 1 month ago

but I would say it should be default behaviour of the built-in reporters.

Maybe, but then there should be an option to turn it off, because to some or in certain cases it doesn't make all that much sense. That's why Knip has custom reporters.

You can also use multiple reporters, e.g. to add a single line to the output of an existing reporter.