Skip to content

Conversation

EzraBrooks
Copy link

Closes #1012.

Still WIP, but opening a draft so I make sure to get it done :)

@@ -0,0 +1,66 @@
import core from '@actions/core';
Copy link
Author

Choose a reason for hiding this comment

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

@webpro Do we want to depend on GitHub Actions as a dependency of Knip? That seems like a lot of overhead for a single log reporter. If not, we could probably easily reverse-engineer the Actions logger. The syntax is pretty simple.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was just happy to reduce deps to this: https://npmgraph.js.org/?q=knip

On the other hand, I don't know what it involves to replicate that logger?

Choose a reason for hiding this comment

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

When i did the initial draft of the reporter, i tried to replicate it using console.log and it did not work.

I think its ok marking actions/core as a peer dependency and just document that when using github actions reporter, @actions/core must also be installed.

Copy link
Author

Choose a reason for hiding this comment

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

I've moved it to optionalDependencies, because I personally am not a fan of using peers for things that are, well.. optional. Thoughts?

Choose a reason for hiding this comment

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

you're right, optional is the best case here

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps I'm exaggerating after trying to cut down on Knip's package size, but looking at their implementation I do have mixed feelings about adding this dependency. An optional dependency is still a dependency.

Even though it's certainly isn't trivial and precision with custom output syntax is required, but essentially we're using three methods and they're all logging to the stdout. Is there any chance you could implement/borrow only the necessary parts?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, sounds good to me. I would be similarly hesitant, which is why I asked. I haven't had a chance to test this against my CI yet (which is why it's still a draft), but I'll try to reimplement it simply to avoid adding the dependency once I do get a chance.

Copy link

@fregante fregante Jun 5, 2025

Choose a reason for hiding this comment

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

optionalDependencies are still installed, even if they don't show up on npmgraph:

Details: https://docs.npmjs.com/cli/v11/configuring-npm/package-json#optionaldependencies

If you don't want it to be a dependency locally you have a few options:

  • make it a plugin (only people who use it install it) — not great
  • offer knip as an action, so it can have its own deps
  • install it on the fly when you detect the GHA environment. This might be troublesome in practice.

Copy link
Contributor

@cylewaitforit cylewaitforit Jun 15, 2025

Choose a reason for hiding this comment

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

If the action took just took in a json report like https://github.com/ataylormet/eslint-annotate-action does, then the core of knip itself wouldn’t need the action dependency.

Disregard, I see that this may not even need that level of complexity for basic annotation.

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.

Thanks for the PR! Would love to see this reporter in Knip.

@@ -0,0 +1,66 @@
import core from '@actions/core';
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I was just happy to reduce deps to this: https://npmgraph.js.org/?q=knip

On the other hand, I don't know what it involves to replicate that logger?

@@ -0,0 +1,32 @@
import core from '@actions/core';
import { ISSUE_TYPES, ISSUE_TYPE_TITLE } from 'src/constants.js';
Copy link

@arthurfiorette arthurfiorette Apr 28, 2025

Choose a reason for hiding this comment

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

Suggested change
import { ISSUE_TYPES, ISSUE_TYPE_TITLE } from 'src/constants.js';
import { ISSUE_TYPES, ISSUE_TYPE_TITLE } from '../constants.js';

Choose a reason for hiding this comment

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

As in my original draft, you cannot use ISSUE_TYPES directly because it has files and not _files.

Copy link
Author

Choose a reason for hiding this comment

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

I see that the disclosure reporter works around this like so:

if (reportType === 'files') reportType = '_files';

Should I just copy that pattern?

Choose a reason for hiding this comment

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

i think so


const cwd = resolve('fixtures/module-resolution-non-std');

test('knip --reporter githubActions (files, unlisted & unresolved)', () => {
Copy link

@arthurfiorette arthurfiorette Apr 28, 2025

Choose a reason for hiding this comment

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

I guess would be great to use the github actions reporter in ci.yml since this is github :)

@EzraBrooks EzraBrooks force-pushed the add-github-actions-reporter branch from 2eb9c6b to 8a881b4 Compare April 28, 2025 19:02
@webpro webpro force-pushed the main branch 5 times, most recently from 83dfdce to 61d09ab Compare May 6, 2025 10:54
@arthurfiorette
Copy link

@EzraBrooks any updates on the review? I can work on it now if you give me permissions to your fork :)

@EzraBrooks
Copy link
Author

Hey, thanks for offering - I got pulled into something last-minute that is taking up basically my entire week this week, sorry about that. Feel free to just cherry-pick my commit elsewhere and amend it, if you'd like.

@webpro webpro force-pushed the main branch 2 times, most recently from ea72d80 to 7787123 Compare May 8, 2025 05:47
@webpro webpro force-pushed the main branch 4 times, most recently from 5a2d249 to 6bd250a Compare June 17, 2025 17:36
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!
5 participants