Skip to content

Conversation

cylewaitforit
Copy link
Contributor

@cylewaitforit cylewaitforit commented Aug 22, 2025

closes #1012

Builds of the work from @arthurfiorette and @EzraBrooks to add a github actions reporter to knip.

Replaces @actions/core dependency with a simple local logger.

An example repo using the reporter can be found at https://github.com/cylewaitforit/knip-test/pull/1/files.

Copy link

pkg-pr-new bot commented Aug 22, 2025

Open in StackBlitz

npm i https://pkg.pr.new/knip@1231

commit: 494bb5d

@arthurfiorette
Copy link
Contributor

I think you should enable this reporter to knip's own test suite

Copy link
Member

@webpro webpro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Would be great to have this reporter baked in 🥞

Any chance there's some kind of actual or test project to see this reporter in action?

};
};

const core = createGitHubActionsLogger();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of a nitpick I guess, but we need this only if the reporter's actually being used, so I think this could go into the reporter function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fair, moved this now.

`${cwd}/src/unused.ts
::error file=${cwd}/src/index.ts::Unlisted dependencies
::error file=${cwd}/src/index.ts::Unlisted dependencies
::error file=${cwd}/src/index.ts,line=8,endLine=8,col=23,endColumn=23::Unresolved imports`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if there's coverage for warn(ing) too.

On a related not, would perhaps be good to find and use a fixture that has unused export and dependency for more diverse output (e.g. fixtures/rules or fixtures/workspaces or fixtures/plugins/nuxt, or multiple separate ones)

Btw I should add pos info to unlisted dependencies (WIP!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests against the suggested fixtures.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

FYI: 7959a11

Copy link
Contributor Author

@cylewaitforit cylewaitforit Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This GithubActions reporter should work in a way where when position info is added it will start using it without it needing to be updated. In order for it to use annotations in the files section the annotation has to have some sort of position info so by default I set it to just fall back to the beginning of the file. Without setting position info it will only show the annotation in the summary and not in the files tab.

Copy link
Contributor

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for picking this up, I have been totally swamped with other work!

I agree with @arthurfiorette that a good application for this would be Knip's own CI here in GitHub Actions!

@cylewaitforit
Copy link
Contributor Author

Thanks so much for picking this up, I have been totally swamped with other work!

I agree with @arthurfiorette that a good application for this would be Knip's own CI here in GitHub Actions!
@EzraBrooks

@webpro Thoughts on this? Would you like the Knip repo to use this reporter in GHA?

@webpro
Copy link
Member

webpro commented Aug 26, 2025

Dogfooding might be a good idea! We can add the --reporter actions or --reporter github-actions somewhere in a workflow. That said, lets not use camelCase on CLI args :)

Any chance we can see it in action somehow somewhere?

@cylewaitforit cylewaitforit marked this pull request as draft September 4, 2025 01:21
@cylewaitforit
Copy link
Contributor Author

Here's an example repo using the github actions reporter
https://github.com/cylewaitforit/knip-test/pull/1/files

@cylewaitforit cylewaitforit marked this pull request as ready for review September 8, 2025 00:21
@cylewaitforit cylewaitforit requested a review from webpro September 8, 2025 00:21
@webpro
Copy link
Member

webpro commented Sep 17, 2025

Thanks a bunch, Cyle! Happy to merge. I've tested things and it LGTM. Any chance @EzraBrooks and @arthurfiorette can confirm this matches their expectations in their project(s) as well?

@EzraBrooks
Copy link
Contributor

This is a great first cut! It would be awesome to later make it annotate the package.json entries for unused dependencies, but I don't think that's necessary for the MVP.

@cylewaitforit
Copy link
Contributor Author

This is a great first cut! It would be awesome to later make it annotate the package.json entries for unused dependencies, but I don't think that's necessary for the MVP.
@EzraBrooks

Great news is that unused dependencies was already accounted and tested for.

I also now added an used dependency to my knip playground test repo now as well if you are interested in seeing that "live in living color".

This actions reporter should also be fairly future tolerant. So that when the work to add pos info in unlisted deps lands it would work without needing changes to this reporter.

@webpro
Copy link
Member

webpro commented Sep 18, 2025

What more can we ask for, Cyle? 🙏 Great job.

@webpro webpro merged commit 0a23450 into webpro-nl:main Sep 18, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

💡 Add github-actions reporter!
4 participants