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

Support for knip 3.x #9

Closed
paales opened this issue Nov 30, 2023 · 6 comments
Closed

Support for knip 3.x #9

paales opened this issue Nov 30, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@paales
Copy link

paales commented Nov 30, 2023

With the latest 3.x version it doesn't run because jsonExt is renamed to json:
https://github.com/graphcommerce-org/graphcommerce/actions/runs/7046140595/job/19177328305#step:5:29

@Codex-
Copy link
Owner

Codex- commented Nov 30, 2023

Thanks for reporting, i'll look into it, likely will release a v2 to support this

@Codex- Codex- added the enhancement New feature or request label Dec 1, 2023
@Codex-
Copy link
Owner

Codex- commented Dec 1, 2023

There have been some changes to how the generated report is structured so working through those slowly. Should be able to finish it up on Monday :)

@Codex-
Copy link
Owner

Codex- commented Dec 6, 2023

Supported with v2, try it and let me know if you have any issues :)

@Codex- Codex- closed this as completed Dec 6, 2023
@gitcoindev
Copy link

hi @codex - thank you! I started using v2 and unfortunately cannot not get annotations to be shown. I am pasting GitHub action log with debugs enabled.

Run Codex-/knip-reporter@v2
- knip-reporter action
  with config:
    token: ###
    command_script_name: knip-ci
    comment_id: Knip-reporter
    annotations: true
    verbose: true
    ignoreResults: false

  - Create check ID
##[debug][createCheckId]: Creating check, name: knip-reporter-annotations-check, title: Knip reporter analysis
##[debug][createCheckId]: Check created (1959[43](https://github.com/gitcoindev/ubiquibot/actions/runs/7194152063/job/19594306400#step:5:44)26809)
  ✔ Create check ID (515ms)
- Running Knip tasks
  - Build knip command
##[debug]knip command: yarn run knip-ci --reporter json
  ✔ Build knip command (3ms)
  - Run knip
  ✔ Run knip (3[46](https://github.com/gitcoindev/ubiquibot/actions/runs/7194152063/job/19594306400#step:5:47)1ms)
  - Parse knip report
##[debug][parseJsonReport]: results summary: {files: 4, dependencies: 4, devDependencies: 8, unlisted: 1}
  ✔ Parse knip report (1ms)
  - Convert report to markdown
##[debug][buildMarkdownSections]: Parsed files (4)
##[debug][buildArraySections]: Parsed dependencies (1)
##[debug][buildArraySections]: Parsed devDependencies (1)
##[debug][buildArraySections]: Parsed unlisted (1)
  ✔ Convert report to markdown (1ms)
✔ Running Knip tasks (3466ms)
- Running comment tasks
  - Prepare comments
##[debug][prepareComments]: 4 sections to prepare
##[debug][createCommentId]: Generated '<!-- Knip-reporter-0 -->'
##[debug][prepareComments]: section 0 added to currentCommentSections
##[debug][prepareComments]: section 1 added to currentCommentSections
##[debug][prepareComments]: section 2 added to currentCommentSections
##[debug][prepareComments]: section 3 added to currentCommentSections
##[debug][prepareComments]: currentCommentSections joined and added to comments
##[debug][createCommentId]: Generated '<!-- Knip-reporter-1 -->'
##[debug][prepareComments]: 1 comments prepared
  ✔ Prepare comments (0ms)
  - Find existing comment IDs
##[debug][getCommentIds]: Existing IDs found: [1828200946]
  ✔ Find existing comment IDs (263ms)
  - Create or update comment
##[debug][createOrUpdateComments]: updated comment (1828200946)
  ✔ Create or update comment (610ms)
  - Delete extraneous comments
  ✔ Delete extraneous comments (0ms)
✔ Running comment tasks (873ms)
##[debug][updateCheckAnnotations]: Begin pushing annotations (0) with level 'failure'
##[debug][updateCheckAnnotations]: Pushing annotations (0) to check 19[59](https://github.com/gitcoindev/ubiquibot/actions/runs/7194152063/job/19594306400#step:5:60)432[68](https://github.com/gitcoindev/ubiquibot/actions/runs/7194152063/job/19594306400#step:5:69)09 completed
Error: knip has resulted in findings, please see the report for more details

I suspected this is due to level 'failure' selected when it should be 'warning' in 'Begin pushing annotations' :

`[updateCheckAnnotations]: Begin pushing annotations (${itemMeta.length}) with level '${

with ignoreResults: false

This works the other way round as expected, when ignore_results are false, it means we do not want to ignore warnings and show annotations. On the other hand when I switched to ignore_results to true, the annotations were not collected as well.

##[debug][updateCheckAnnotations]: Begin pushing annotations (0) with level 'warning'
##[debug][updateCheckAnnotations]: Pushing annotations (0) to check 19595192445 completed

the same pull request with my forked implementation on knip 2.43.0 collects 15 annotations

- knip-reporter action
  with config:
    token: ###
    command_script_name: knip-ci
    comment_id: Knip-reporter
    annotations: true
    verbose: true
    ignoreResults: false

  - Create check ID
##[debug][createCheckId]: Creating check, name: knip-reporter-annotations-check, title: Knip reporter analysis
##[debug][createCheckId]: Check created (19595753727)
  ✔ Create check ID (467ms)
- Running Knip tasks
  - Build knip command
##[debug]knip command: yarn run knip-ci --reporter jsonExt
  ✔ Build knip command (3ms)
  - Run knip
  ✔ Run knip (6602ms)
  - Parse knip report
##[debug][parseJsonReport]: results summary: {files: 4, dependencies: 4, devDependencies: 8, unlisted: 1, exports: 10, types: 1, enumMembers: 2, classMembers: 1}
  ✔ Parse knip report (1ms)
  - Convert report to markdown
##[debug][buildMarkdownSections]: Parsed files files (4)
##[debug][buildArraySection]: package.json result {"name":"@actions/core"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"@netlify/functions"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"@probot/adapter-aws-lambda-serverless"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"js-yaml"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildMarkdownSections]: Parsed arrays dependencies (1)
##[debug][buildMarkdownSections]: Total annotations 0
##[debug][buildArraySection]: package.json result {"name":"@types/jest"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"@types/source-map-support"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"jest"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"nock"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"smee-client"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"source-map-support"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"supabase"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: package.json result {"name":"ts-jest"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildMarkdownSections]: Parsed arrays devDependencies (1)
##[debug][buildMarkdownSections]: Total annotations 0
##[debug][buildArraySection]: src/index.ts result {"name":"@octokit/webhooks"}
##[debug][buildArraySection] result: [object Object]
##[debug][buildMarkdownSections]: Parsed arrays unlisted (1)
##[debug][buildMarkdownSections]: Total annotations 0
##[debug][buildArraySection]: src/helpers/gpt.ts result {"name":"gptContextTemplate","line":16,"col":14,"pos":985}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/helpers/issue.ts result {"name":"getCommentsOfIssue","line":221,"col":14,"pos":6453}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/helpers/user.ts result {"name":"getOrgMembershipOfUser","line":36,"col":14,"pos":986}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/types/shared.ts result {"name":"TURL","line":3,"col":14,"pos":56}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/utils/address.ts result {"name":"shortenEthAddress","line":1,"col":14,"pos":13}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/handlers/payout/action.ts result {"name":"unusedAction","line":334,"col":14,"pos":11973}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/handlers/payout/action.ts result {"name":"unusedAction2","line":3[39](https://github.com/gitcoindev/ubiquibot/actions/runs/7194672174/job/19595737100#step:5:40),"col":14,"pos":12075}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/handlers/payout/action.ts result {"name":"unusedAction3","line":344,"col":14,"pos":12179}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/adapters/telegram/helpers/client.ts result {"name":"telegramNotifier","line":43,"col":23,"pos":1218}
##[debug][buildArraySection] result: [object Object]
##[debug][buildArraySection]: src/handlers/comment/handlers/payout.ts result {"name":"payout","line":15,"col":14,"pos":510}
##[debug][buildArraySection] result: [object Object]
##[debug][buildMarkdownSections]: Parsed arrays exports (8)
##[debug][buildMarkdownSections]: Total annotations 10
##[debug][buildArraySection]: src/handlers/payout/post.ts result {"name":"CreatorCommentResult","line":12,"col":18,"pos":636}
##[debug][buildArraySection] result: [object Object]
##[debug][buildMarkdownSections]: Parsed arrays types (1)
##[debug][buildMarkdownSections]: Total annotations 11
##[debug][buildMarkdownSections]: Parsed maps enumMembers (1)
##[debug][buildMarkdownSections]: Parsed maps classMembers (1)
  ✔ Convert report to markdown (3ms)
✔ Running Knip tasks (6609ms)
- Running comment tasks
  - Prepare comments
##[debug][prepareComments]: 8 sections to prepare
##[debug][createCommentId]: Generated '<!-- Knip-reporter-0 -->'
##[debug][prepareComments]: section 0 added to currentCommentSections
##[debug][prepareComments]: section 1 added to currentCommentSections
##[debug][prepareComments]: section 2 added to currentCommentSections
##[debug][prepareComments]: section 3 added to currentCommentSections
##[debug][prepareComments]: section 4 added to currentCommentSections
##[debug][prepareComments]: section 5 added to currentCommentSections
##[debug][prepareComments]: section 6 added to currentCommentSections
##[debug][prepareComments]: section 7 added to currentCommentSections
##[debug][prepareComments]: currentCommentSections joined and added to comments
##[debug][createCommentId]: Generated '<!-- Knip-reporter-1 -->'
##[debug][prepareComments]: 1 comments prepared
  ✔ Prepare comments (0ms)
  - Find existing comment IDs
##[debug][getCommentIds]: Existing IDs found: [1828200946]
  ✔ Find existing comment IDs (181ms)
  - Create or update comment
##[debug][createOrUpdateComments]: updated comment (1828200946)
  ✔ Create or update comment (4[42](https://github.com/gitcoindev/ubiquibot/actions/runs/7194672174/job/19595737100#step:5:43)ms)
  - Delete extraneous comments
  ✔ Delete extraneous comments (0ms)
✔ Running comment tasks ([62](https://github.com/gitcoindev/ubiquibot/actions/runs/7194672174/job/19595737100#step:5:63)3ms)
##[debug][updateCheckAnnotations]: Begin pushing annotations (15) with level 'failure'
##[debug][updateCheckAnnotations]: Processing 0...14 of 14

Now I am pretty confused, I would be grateful if you had a look on this, perhaps knip v3 with --json does not output the same data as knip 2.43.0 with --jsonExt?

@gitcoindev
Copy link

@Codex- after a few hours of debugging I found the culprit - project used typescript 4.9 and knip 3.x does not output annotations in json then. Problem was solved after I upgraded dev dependencies.

@Codex-
Copy link
Owner

Codex- commented Dec 13, 2023

That's actually really helpful to know, thanks for tracking that down

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

No branches or pull requests

3 participants