Skip to content

Add AI skill that checks for any unused exports#1818

Open
kyoto wants to merge 1 commit into
openshift:mainfrom
kyoto:find-unused-exports
Open

Add AI skill that checks for any unused exports#1818
kyoto wants to merge 1 commit into
openshift:mainfrom
kyoto:find-unused-exports

Conversation

@kyoto
Copy link
Copy Markdown
Member

@kyoto kyoto commented Apr 16, 2026

Also removes the unnecessary exports that it found

Summary by CodeRabbit

  • Documentation

    • Added Cursor skill documentation for identifying unused exports in TypeScript projects.
  • Chores

    • Internal code refactoring to optimize module exports and accessibility.
    • Updated TypeScript configuration for improved test environment setup.

@kyoto kyoto added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 16, 2026
@openshift-ci openshift-ci Bot requested review from syedriko and xrajesh April 16, 2026 06:28
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 16, 2026

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1 similar comment
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Apr 16, 2026

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 128a976d-36bb-48e9-bd77-aede297ce050

📥 Commits

Reviewing files that changed from the base of the PR and between 40d95eb and c22c970.

📒 Files selected for processing (5)
  • .cursor/skills/unused-exports/SKILL.md
  • src/flags.ts
  • src/hooks/useOpenOLS.ts
  • src/types.ts
  • unit-tests/tsconfig.json
✅ Files skipped from review due to trivial changes (2)
  • unit-tests/tsconfig.json
  • .cursor/skills/unused-exports/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/hooks/useOpenOLS.ts
  • src/types.ts
  • src/flags.ts

📝 Walkthrough

Walkthrough

This PR internalizes four previously exported items across three source files (FLAG_LIGHTSPEED_PLUGIN, useOpenOLS, HistoryCompression), adds a Cursor skill documenting the unused-exports detection workflow, and creates a TypeScript configuration for the unit-tests directory. The functionality of internal references and implementations remains unchanged.

Changes

Removal of Unused Exports

Layer / File(s) Summary
Export visibility reductions
src/flags.ts, src/hooks/useOpenOLS.ts, src/types.ts
FLAG_LIGHTSPEED_PLUGIN changed from exported to internal constant; useOpenOLS changed from named export to internal const while preserving default export; HistoryCompression type changed from exported to internal. Implementations and internal usages remain unchanged.
Unused exports detection workflow
.cursor/skills/unused-exports/SKILL.md
New Cursor skill documentation defining the workflow to identify unused exports using ts-unused-exports@11.0.1, with filtering rules for externally consumed exports referenced in package.json and console-extensions.json, and result grouping instructions.
Unit test TypeScript configuration
unit-tests/tsconfig.json
New TypeScript configuration extending the root tsconfig.json with include paths covering unit tests, source directory, and shared typings, enabling proper compilation in the test directory context.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Four exports tucked away from sight,
Their hidden work still shining bright,
The skill reveals which ones were lost,
And tests compile without cost—
Clean exports, now internal tight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: adding an AI skill that checks for unused exports, which is confirmed by the new Cursor skill documentation file and the removal of unused exports from the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@kyoto
Copy link
Copy Markdown
Member Author

kyoto commented Apr 16, 2026

/cherry-pick release-4.19
/cherry-pick pattern-fly-5

@openshift-cherrypick-robot
Copy link
Copy Markdown

@kyoto: once the present PR merges, I will cherry-pick it on top of pattern-fly-5, release-4.19 in new PRs and assign them to you.

Details

In response to this:

/cherry-pick release-4.19
/cherry-pick pattern-fly-5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
.cursor/skills/unused-exports/SKILL.md (1)

23-31: Broaden module-path resolution to avoid false positives.

The current wording implies exposedModules always maps to src/<path>.ts; this can miss *.tsx or index.ts(x) entry points.

Proposed doc tweak
-Read `package.json` field `consolePlugin.exposedModules`. Each value is a module
-path relative to `src/` (e.g. `"./flags"` → `src/flags.ts`). These modules are
+Read `package.json` field `consolePlugin.exposedModules`. Each value is a module
+path relative to `src/` (e.g. `"./flags"` may resolve to `src/flags.ts`,
+`src/flags.tsx`, `src/flags/index.ts`, or `src/flags/index.tsx`). These modules are
 loaded at runtime by the OpenShift console framework — their exports are used
 externally even though nothing inside this repo imports them.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.cursor/skills/unused-exports/SKILL.md around lines 23 - 31, The docs assume
consolePlugin.exposedModules always maps to src/<path>.ts which causes false
negatives for .tsx or index files; update the module-path resolution guidance
to, when mapping each exposedModules entry to a file, try resolving the exact
path as given and fall back to src/<path>.ts, src/<path>.tsx,
src/<path>/index.ts, and src/<path>/index.tsx (and accept explicit extensions),
and when parsing console-extensions.json $codeRef values map the ModuleName back
using that broadened resolution so export references (ModuleName or
ModuleName.exportName) correctly identify entry points.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.cursor/skills/unused-exports/SKILL.md:
- Around line 23-31: The docs assume consolePlugin.exposedModules always maps to
src/<path>.ts which causes false negatives for .tsx or index files; update the
module-path resolution guidance to, when mapping each exposedModules entry to a
file, try resolving the exact path as given and fall back to src/<path>.ts,
src/<path>.tsx, src/<path>/index.ts, and src/<path>/index.tsx (and accept
explicit extensions), and when parsing console-extensions.json $codeRef values
map the ModuleName back using that broadened resolution so export references
(ModuleName or ModuleName.exportName) correctly identify entry points.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 15cf0746-3497-466b-95e3-ceb5f7f323ea

📥 Commits

Reviewing files that changed from the base of the PR and between e5f50e2 and 7f0f2a0.

📒 Files selected for processing (6)
  • .cursor/skills/unused-exports/SKILL.md
  • src/error.ts
  • src/flags.ts
  • src/hooks/useOpenOLS.ts
  • src/redux-reducers.ts
  • src/types.ts

@joshuawilson
Copy link
Copy Markdown
Contributor

Do you expect to run this often? It feels like you run it once and then only when the exports drift.

You could get 90% of this in CLAUDE.md with "To check for unused exports, run npx ts-unused-exports tsconfig.json --findCompletelyUnusedFiles --showLineNumber --searchNamespaces. Exports referenced via $codeRef in console-extensions.json are consumed externally by the OpenShift console framework, filter those from the results."

Alternatively you could use "knip". It finds unused exports, files, dependencies, and types in one pass. Crucially, it has native entry point configuration you define your entry points in knip.json and it filters automatically, eliminating the need for the manual Steps 2-3 entirely. You could add knip to the lint pipeline and remove the skill entirely.

@kyoto kyoto force-pushed the find-unused-exports branch from 7f0f2a0 to 40d95eb Compare May 14, 2026 08:28
@kyoto
Copy link
Copy Markdown
Member Author

kyoto commented May 14, 2026

Thanks @joshuawilson

I think there's some value in having this as a separate skill since it is something that will only be used occassionally. (Not something that the AI should consider for every task since that's probably using tokens for minimal value.)

I reworked the skill to be much more succinct and also pinned the version of ts-unused-exports to avoid potential supply chain attacks.

@kyoto
Copy link
Copy Markdown
Member Author

kyoto commented May 14, 2026

Override test failure unrelated to this change:
/override "Red Hat Konflux / e2e-console-pf6 / lightspeed-console"

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 14, 2026

@kyoto: Overrode contexts on behalf of kyoto: Red Hat Konflux / e2e-console-pf6 / lightspeed-console

Details

In response to this:

Override test failure unrelated to this change:
/override "Red Hat Konflux / e2e-console-pf6 / lightspeed-console"

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Also removes the unnecessary exports that it found
@kyoto kyoto force-pushed the find-unused-exports branch from 40d95eb to c22c970 Compare May 15, 2026 05:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants