Repository navigation
chore(pre-commit): add deep import check hook - #401
CatherineSue wants to merge 2 commits into
Conversation
Summary of ChangesHello @CatherineSue, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new pre-commit hook to improve code readability and maintainability by preventing deeply nested internal Rust imports. The hook identifies and flags Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughThis PR introduces a new linting check for deeply nested Rust imports across CI/CD pipelines and local development. It adds a Bash script to detect imports exceeding four path segments, integrates it into GitHub Actions and pre-commit hooks, and reorders authors in the Python gRPC client configuration. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Comment |
Adds a pre-commit hook that rejects internal Rust imports (crate::, super::) with more than 4 path segments to keep import paths shallow and readable.
91b6771 to
dd67bd8
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new pre-commit hook to detect and flag deeply nested internal imports in Rust code, aiming to improve code readability and module structure. A potential argument injection vulnerability exists in the grep command within scripts/check-deep-imports.sh, which could lead to denial-of-service or bypass scenarios if filenames start with a hyphen. Additionally, the current detection logic could be made more robust by enhancing the regular expression to cover pub use statements and glob imports (*) for more comprehensive coverage.
Description
Problem
Deeply nested internal imports (e.g.
use crate::a::b::c::d::e) hurt readability and often indicate missing re-exports or overly coupled module structure.Solution
Adds a pre-commit hook and CI check that flags
crate::andsuper::import paths with more than 4 path segments. External crate imports are ignored since those are out of our control.Changes
scripts/check-deep-imports.sh— bash script that greps.rsfiles for deeply nested internal imports.pre-commit-config.yaml— registercheck-deep-importsas a local pre-commit hook for Rust files.github/workflows/pr-test-rust.yml— addlint-importsCI job that runs the same check on every PR, gated in thefinishjobTest Plan
Run against the codebase to verify it catches known violations:
bash scripts/check-deep-imports.sh $(find . -name '*.rs' -not -path './target/*')Currently flags 2 internal violations:
model_gateway/src/routers/grpc/common/stages/mod.rs:12model_gateway/src/routers/grpc/pipeline.rs:12Checklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassesSummary by CodeRabbit