Skip to content

Skip the export check for shorthand ambient modules - #111

Merged
CodeDeficient merged 1 commit into
mainfrom
fix/shorthand-ambient-modules
Oct 26, 2026
Merged

CodeDeficient merged 1 commit into
mainfrom
fix/shorthand-ambient-modules

Conversation

@CodeDeficient

@CodeDeficient CodeDeficient commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

User description

Fixes #100.

A project shim such as declare module 'lucide-react'; types every import from that module as any, so TypeScript accepts any name. KarpeSlop's checker resolved the import to the shim and found no exports. It then reported every imported name as a critical hallucinated_import.

This PR skips the export check when a module is declared with a bodiless declare module 'x';.

Impact

TruckFull (210k-line Next.js app with shims for lucide-react and @radix-ui/react-slot), --quiet:

Before After
critical findings 845 20
Lies axis 20.0 7.8

The 20 that remain are real: a missing @/hooks/useAuth, plus prototypes in a gitignored tmp/ folder (#101).

Testing

  • New regression test: it fails without the guard and passes with it. npm test passes all 158 tests, and the typecheck is clean.
  • Reviewed with /review (reviewer on Haiku 5.5): PASS. Two P3 notes are filed as a follow-up issue.

🤖 Generated with Claude Code


CodeAnt-AI Description

Stop false missing-import errors for shimmed modules

What Changed

  • Imports from shorthand module declarations like declare module 'x'; no longer trigger false missing-export findings, since TypeScript accepts any import name from these modules.

Impact

✅ Fewer false import errors in projects with module shims
✅ Strict checks no longer fail because of these shims

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Bug Fixes
    • Import checks no longer report invalid named or default exports from modules covered by shorthand ambient declarations, which TypeScript treats as any.
  • Tests
    • Added coverage for imports from shorthand ambient modules.
  • Documentation
    • Updated the unreleased changelog to describe this behavior.

A project shim such as `declare module 'lucide-react';` types every
import from that module as any, so TypeScript accepts any name. The
checker resolves the import to the shim, getExportsOfModule returns
nothing, and every imported name was reported as a critical
hallucinated_import: 825 false findings on a Next.js app with shims
for lucide-react and @radix-ui/react-slot, enough to fail --strict.

Fixes #100

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt Review Status

✅  Review completed

Status Commit Started (UTC) Finished (UTC)
✅  Reviewed your PR ba91bb5 Oct 26, 2026 · 12:12 12:15

@codeant-ai

codeant-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

checkImports skips named and default export validation for modules declared with shorthand ambient declarations. A test covers imports from such a module, and the changelog records the behavior.

Changes: Shorthand ambient module imports

Layer / File(s) Summary
Skip export checks for shorthand declarations
imports.ts, tests/rules.test.ts, CHANGELOG.md
checkImports skips export validation when the module symbol has an ambient declaration with no body. A test checks named and default imports, and the changelog describes the change.

Priority: Not assessed

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: High

Possibly related PRs

Suggested reviewers: claude

Merge Risk: Low · up to ba91b

Some valid imports from shorthand ambient modules can still be flagged as critical findings. The affected case is narrow, so this is mergeable with a targeted follow-up.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each import name,
A shorthand module changes the game.
No export list is known to see,
So checks step past it quietly.
The test and changelog mark the way.

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

@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Oct 26, 2026
@CodeDeficient
CodeDeficient merged commit 78fe06e into main Oct 26, 2026
2 of 3 checks passed
@codeant-ai

codeant-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

CodeAnt  CodeAnt Nitpicks

1 code suggestion

1. When a shorthand declaration masks react, this continue suppresses the curated useRouter-from-react finding, allowing the known wrong import through.

Incorrect condition logic · imports.ts:559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shorthand ambient module declarations cause hallucinated_import false positives

1 participant