fix: support extension-only inputs in detect_lang#33
Conversation
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesLanguage Detection
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_detect_language.py (1)
4-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd test coverage for case-insensitive extension lookup.
The
.lower()normalization indetect_langis a key part of this change but no test exercises it. A single assertion for an uppercase extension (e.g.,.PYormain.PY) would verify this path.🧪 Suggested addition
def test_detect_lang_with_extension_only(): assert detect_lang(".py") == "python" assert detect_lang(".js") == "javascript" assert detect_lang(".cpp") == "cpp" assert detect_lang(".md") == "markdown" assert detect_lang(".json") == "json" + assert detect_lang(".PY") == "python" + + def test_detect_lang_with_path(): assert detect_lang("main.py") == "python" assert detect_lang("index.js") == "javascript" assert detect_lang("src/config.yaml") == "yaml" + assert detect_lang("main.PY") == "python"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_detect_language.py` around lines 4 - 21, Add an assertion to the existing detect_lang tests covering an uppercase extension, such as ".PY" or "main.PY", and verify it returns the same language as the lowercase form. Keep the coverage focused on the case-insensitive normalization in detect_lang.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/test_detect_language.py`:
- Around line 4-21: Add an assertion to the existing detect_lang tests covering
an uppercase extension, such as ".PY" or "main.PY", and verify it returns the
same language as the lowercase form. Keep the coverage focused on the
case-insensitive normalization in detect_lang.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 546ff2b4-d3eb-47fb-a0c6-de6801c88b96
📒 Files selected for processing (2)
repo2readme/utils/detect_language.pytests/test_detect_language.py
There was a problem hiding this comment.
Pull request overview
This PR fixes language detection when detect_lang() is called with extension-only metadata (e.g., .py) by correctly treating the input as an extension when os.path.splitext() yields an empty extension.
Changes:
- Update
detect_lang()to handle extension-only inputs while preserving path/filename behavior. - Add regression tests for extension-only inputs, normal paths, and unknown extensions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_detect_language.py | Adds regression coverage for extension-only and path-based language detection. |
| repo2readme/utils/detect_language.py | Fixes detection logic to accept extension-only inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def detect_lang(path:str): | ||
| _,extension=os.path.splitext(path) | ||
| return EXTENSION_LANGUAGE_MAP.get(extension,"unknown") No newline at end of file | ||
| if not extension and path.startswith("."): | ||
| extension=path | ||
| return EXTENSION_LANGUAGE_MAP.get(extension.lower(),"unknown") |
|
@deepmhatre13 See the pr is labelled with ECSoC26 |
Fixes #32
Summary
This PR fixes a bug where
detect_lang()always returned"unknown"when called with extension-only metadata (e.g..py,.js,.cpp).Root Cause
The loaders store only the file extension in
doc.metadata["file_type"].Later,
detect_lang()callsos.path.splitext()on that value again.For example:
As a result, the extracted extension becomes an empty string and every lookup falls back to
"unknown".Changes
detect_lang()Testing
Result:
Summary by CodeRabbit
Bug Fixes
.gitignore.Tests