Skip to content

Add knip linter#36442

Merged
silverwind merged 13 commits into
go-gitea:mainfrom
silverwind:knip
Jan 24, 2026
Merged

Add knip linter#36442
silverwind merged 13 commits into
go-gitea:mainfrom
silverwind:knip

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Jan 24, 2026

This adds knip, a tool to find unused files, dependencies and exports in JS. Fixed all discovered issues.

  1. knip apparently has some issue resolving imports from d.ts to .ts so I worked around it by moving the two affected types to where they are used.
  2. I don't know why modules/fomantic/dropdown.ts had a new typescript error, but I fixed it.
  3. Use named export for EsbuildPlugin, I think this was added recently.

This adds knip, a tool to find unused exports in JS. Fixed all
discovered issues.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 24, 2026
@silverwind silverwind requested a review from Copilot January 24, 2026 00:53
@silverwind silverwind added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Jan 24, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds knip to the frontend toolchain to detect unused exports and incorporates cleanup changes found by the tool.

Changes:

  • Add knip as a dev dependency and commit the updated lockfile.
  • Introduce knip.config.ts and run knip as part of make lint-js / make lint-js-fix.
  • Remove unused exports and adjust global typings accordingly.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
web_src/js/types.ts Removes an exported type and a config type; intended cleanup after knip findings.
web_src/js/markup/render-iframe.ts Makes an internal helper no longer exported.
web_src/js/markup/refissue.ts Makes an internal helper no longer exported.
web_src/js/globals.d.ts Inlines window.config typing instead of referencing types.ts.
package.json Adds knip to devDependencies.
pnpm-lock.yaml Updates lockfile for knip and transitive dependencies.
knip.config.ts Adds knip configuration (entry points, project globs, excludes).
Makefile Runs knip during JS lint and lint-fix targets.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web_src/js/types.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread templates/base/head_script.tmpl
@silverwind silverwind changed the title Add knip Add knip linter Jan 24, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 24, 2026
@ChristopherHX
Copy link
Copy Markdown
Contributor

ChristopherHX commented Jan 24, 2026

I just noticed that the make lint-js-fix currently has side effects, e.g. it alters package.json by removing some deps. Otherwise actually a nice tool.

Those are for me at least in package.json
"@primer/octicons": "19.21.2",
"@resvg/resvg-wasm": "2.6.2",
"webpack-cli": "6.0.1",
"@eslint/json": "0.14.0",
"markdownlint-cli": "0.47.0",
"material-icon-theme": "5.31.0",
"nolyfill": "1.0.44",
"spectral-cli-bundle": "1.0.3",
"svgo": "4.0.0",
"updates": "17.0.8",
"vitest": "4.0.18",

@silverwind
Copy link
Copy Markdown
Member Author

Odd, it shouldn't do that because I've disabled the dependency modules (too many exclusions would be needed). Will test it.

Comment thread Makefile
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Jan 24, 2026

Fixed this by enabling the dependency modules. A couple of exclusions were needed because knip currently can not detect usage in Makefile or when reading data directly out of node_modules. Now make lint-js-fix does not alter package.json anymore.

Opened webpro-nl/knip#1486 for the --fix bug.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 13 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@ChristopherHX ChristopherHX left a comment

Choose a reason for hiding this comment

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

Works now correctly on my end

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 24, 2026
@silverwind silverwind enabled auto-merge (squash) January 24, 2026 12:48
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jan 24, 2026
@silverwind silverwind merged commit 12a81d3 into go-gitea:main Jan 24, 2026
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Jan 24, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Jan 24, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 26, 2026
* giteaofficial/main:
  Normalize guessed languages for code highlighting (go-gitea#36450)
  Add `knip` linter (go-gitea#36442)
  Fix various bugs (go-gitea#36446)
  Update tool dependencies (go-gitea#36445)
  Update JS dependencies, adjust webpack config, misc fixes (go-gitea#36431)
  fix: Improve image captcha contrast for dark mode (go-gitea#36265)
  Refactor template render (go-gitea#36438)
  Add documentation for markdown anchor post-processing (go-gitea#36443)
  Fix markup heading parsing, fix emphasis parsing (go-gitea#36284)
  Front port changelog for 1.25.4 (go-gitea#36432)
  Bugfix: Potential incorrect runID in run status update (go-gitea#36437)
  Restrict branch naming when new change matches with protection rules (go-gitea#36405)
@silverwind silverwind deleted the knip branch March 2, 2026 05:00
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants