-
Notifications
You must be signed in to change notification settings - Fork 0
docs: add comprehensive code quality standards guide #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
96ad22b
docs: add comprehensive code quality standards guide
d-ulker 8fa565c
fix(docs): update code quality guide based on feedback
d-ulker 09eb2dd
fix(docs): clarify file availability and restore gitmessage template
d-ulker 7d3e358
fix(docs): address all 9 nitpick comments for better accuracy
d-ulker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # SAMO-DL Commit Message Template | ||
| # | ||
| # Quick setup: | ||
| # git config commit.template .gitmessage.txt | ||
| # # To make it global: git config --global commit.template "$(pwd)/.gitmessage.txt" | ||
| # | ||
| # Format: <type>(<scope>)!: <subject> | ||
| # (scope is optional; add "!" for breaking changes) | ||
| # Body: explain what and why, wrapped at ~72 chars per line | ||
| # Footer: references and BREAKING CHANGE notes | ||
| # | ||
| # Types: | ||
| # feat: A new feature | ||
| # fix: A bug fix | ||
| # docs: Documentation only changes | ||
| # style: Formatting, whitespace, missing semicolons, no code change | ||
| # refactor: Code change that neither fixes a bug nor adds a feature | ||
| # perf: A code change that improves performance | ||
| # test: Adding missing tests or correcting existing tests | ||
| # build: Changes to build system or external dependencies | ||
| # ci: Changes to CI configuration files and scripts | ||
| # chore: Other changes that don't modify src or test files | ||
| # revert: Reverts a previous commit | ||
| # | ||
| # Rules: | ||
| # - ONE purpose per commit (no "and", "also", "plus") | ||
| # - Subject line β€ 50 characters | ||
| # - Use imperative mood ("Add" not "Added") | ||
| # - No period at end of subject line | ||
| # - Wrap body at ~72 characters per line | ||
| # - Reference issues/PRs in footer (e.g., "Closes #123") | ||
| # - Use "BREAKING CHANGE: ..." in footer for breaking changes | ||
| # | ||
| # Examples: | ||
| # feat(auth): add login with email magic links | ||
| # fix(loader): resolve memory leak in model loading | ||
| # perf(infer): cache tokenizer to reduce setup time | ||
| # refactor(rate-limit): simplify token bucket logic | ||
| # docs(api): update inference usage examples | ||
| # style: run formatter across repo | ||
| # build: bump torch to 2.4.x | ||
| # ci: parallelize test matrix | ||
| # revert: revert "feat(auth): add magic links" | ||
| # feat(core)!: switch default precision to bfloat16 | ||
| # BREAKING CHANGE: default precision is now bfloat16; set | ||
| # SAMO_PRECISION=float32 to keep previous behavior. | ||
| # Closes #174 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,209 @@ | ||||||||||||||||||||||||||||||||||||
| # SAMO-DL Code Quality Standards | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π― Mission: Prevent Monster PRs Forever | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| This document outlines the **strict rules** and **automated enforcement** designed to prevent the creation of massive, unfocused pull requests that slow down development and make code reviews impossible. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π« THE PROBLEM WE SOLVE | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Monster PRs** are pull requests that: | ||||||||||||||||||||||||||||||||||||
| - Change 100+ files | ||||||||||||||||||||||||||||||||||||
| - Add 1000+ lines of code | ||||||||||||||||||||||||||||||||||||
| - Mix multiple concerns (API + tests + docs + infrastructure) | ||||||||||||||||||||||||||||||||||||
| - Take weeks to review | ||||||||||||||||||||||||||||||||||||
| - Cause merge conflicts | ||||||||||||||||||||||||||||||||||||
| - Block progress | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## β THE SOLUTION: Micro-PRs Only | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Hard Limits (Automated Enforcement)** | ||||||||||||||||||||||||||||||||||||
| ```yaml | ||||||||||||||||||||||||||||||||||||
| # GitHub Actions - PR Size Guard | ||||||||||||||||||||||||||||||||||||
| max_files_changed: 50 # HARD STOP at 50 files | ||||||||||||||||||||||||||||||||||||
| max_lines_changed: 1500 # HARD STOP at 1500 lines | ||||||||||||||||||||||||||||||||||||
| max_commits_per_pr: 5 # HARD STOP at 5 commits | ||||||||||||||||||||||||||||||||||||
| branch_lifetime: 72h # Auto-close or require split after 72h (extensions available for complex changes) | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| #### Requirement: PR purpose must be exactly one sentence | ||||||||||||||||||||||||||||||||||||
| - β "Add user authentication system" | ||||||||||||||||||||||||||||||||||||
| - β "Fix memory leak in model loading" | ||||||||||||||||||||||||||||||||||||
| - β "Improve model architecture and fix bugs" *(TWO THINGS!)* | ||||||||||||||||||||||||||||||||||||
| - β "Refactor training pipeline" *(TOO VAGUE!)* | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π οΈ AUTOMATED ENFORCEMENT | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **1. Local Hooks (pre-commit + commit-msg)** | ||||||||||||||||||||||||||||||||||||
| Use the pre-commit framework (versioned via `.pre-commit-config.yaml`) to run format/lint/type/security checks on staged files. Enforce commit message format via a `commit-msg` hook (e.g., Commitizen). | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Notes:** | ||||||||||||||||||||||||||||||||||||
| - Branch naming and "single purpose" are enforced in CI (see PR Scope Checker), not locally. | ||||||||||||||||||||||||||||||||||||
| - Hooks run automatically once installed (`pre-commit install` and `pre-commit install --hook-type commit-msg`). | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **2. PR Scope Checker** | ||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||
| python scripts/check_pr_scope.py --strict | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| > **Note:** The PR scope checker script is available in the repository and actively maintained. | ||||||||||||||||||||||||||||||||||||
| Validates: | ||||||||||||||||||||||||||||||||||||
| - File count β€ 50 | ||||||||||||||||||||||||||||||||||||
| - Line changes β€ 1500 | ||||||||||||||||||||||||||||||||||||
| - Single purpose (no mixing concerns) | ||||||||||||||||||||||||||||||||||||
| - Branch naming compliance | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **3. CI Pipeline Checks** | ||||||||||||||||||||||||||||||||||||
| GitHub Actions automatically: | ||||||||||||||||||||||||||||||||||||
| - Runs scope validation on PR creation | ||||||||||||||||||||||||||||||||||||
| - Fails builds that exceed limits | ||||||||||||||||||||||||||||||||||||
| - Prevents merging of out-of-scope PRs | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π DEVELOPMENT WORKFLOW | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Before Creating a Branch** | ||||||||||||||||||||||||||||||||||||
| ```md | ||||||||||||||||||||||||||||||||||||
| # Answer these questions: | ||||||||||||||||||||||||||||||||||||
| 1. Can I describe this in ONE sentence? | ||||||||||||||||||||||||||||||||||||
| 2. Will this affect < 50 files? | ||||||||||||||||||||||||||||||||||||
| 3. Can I complete this in < 4 hours? | ||||||||||||||||||||||||||||||||||||
| 4. Is this EXACTLY ONE concern? | ||||||||||||||||||||||||||||||||||||
| 5. Am I mixing API + tests + docs? | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # If ANY answer is NO: Split into separate PRs | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Branch Naming Convention** | ||||||||||||||||||||||||||||||||||||
| ```text | ||||||||||||||||||||||||||||||||||||
| feat/short-description # New features | ||||||||||||||||||||||||||||||||||||
| fix/short-description # Bug fixes | ||||||||||||||||||||||||||||||||||||
| chore/short-description # Build/tooling changes | ||||||||||||||||||||||||||||||||||||
| refactor/short-description # Code restructuring | ||||||||||||||||||||||||||||||||||||
| docs/short-description # Documentation | ||||||||||||||||||||||||||||||||||||
| test/short-description # Test additions | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Examples:** | ||||||||||||||||||||||||||||||||||||
| - β `feat/add-user-auth` | ||||||||||||||||||||||||||||||||||||
| - β `fix/validate-input` | ||||||||||||||||||||||||||||||||||||
| - β `chore/update-deps` | ||||||||||||||||||||||||||||||||||||
| - β `refactor/simplify-logic` | ||||||||||||||||||||||||||||||||||||
| - β `feat/add-auth-and-fix-bugs` *(multiple concerns)* | ||||||||||||||||||||||||||||||||||||
| - β `fix-stuff` *(too vague)* | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Commit Message Format** | ||||||||||||||||||||||||||||||||||||
| ```gitcommit | ||||||||||||||||||||||||||||||||||||
| <type>(<scope>): <subject> | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| <body - optional> | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
| **Examples:** | ||||||||||||||||||||||||||||||||||||
| ```gitcommit | ||||||||||||||||||||||||||||||||||||
| feat: add JWT token authentication | ||||||||||||||||||||||||||||||||||||
| fix: resolve memory leak in model loading | ||||||||||||||||||||||||||||||||||||
| chore: update Python dependencies | ||||||||||||||||||||||||||||||||||||
| refactor: simplify rate limiter logic | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## ποΈ CODE QUALITY TOOLS | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Automated Tools** | ||||||||||||||||||||||||||||||||||||
| - **Ruff**: Ultra-fast code formatting, linting, and import sorting (replaces Black, isort, flake8) | ||||||||||||||||||||||||||||||||||||
| - **pylint**: Advanced code analysis | ||||||||||||||||||||||||||||||||||||
| - **mypy**: Type checking | ||||||||||||||||||||||||||||||||||||
| - **bandit**: Security scanning | ||||||||||||||||||||||||||||||||||||
| - **safety**: Dependency vulnerability checks | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Pre-commit Hooks** | ||||||||||||||||||||||||||||||||||||
| Run automatically on commit: | ||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||
| pre-commit install # Install hooks | ||||||||||||||||||||||||||||||||||||
| pre-commit run --all-files # Run on all files | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Development Commands** | ||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||
| make format # Format code | ||||||||||||||||||||||||||||||||||||
| make lint # Run linters | ||||||||||||||||||||||||||||||||||||
| make test # Run tests | ||||||||||||||||||||||||||||||||||||
| make quality-check # Run all quality checks | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π¨ EMERGENCY OVERRIDES | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Only for critical production issues:** | ||||||||||||||||||||||||||||||||||||
| ```yaml | ||||||||||||||||||||||||||||||||||||
| override_label: "EMERGENCY-OVERRIDE" | ||||||||||||||||||||||||||||||||||||
| required_approvers: 2 | ||||||||||||||||||||||||||||||||||||
| max_override_per_week: 1 | ||||||||||||||||||||||||||||||||||||
| auto_close_after: 8h | ||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| > **Note:** Overrides require label + 2 approvers + admin "bypass PR requirements" permission, or a temporary policy change. GitHub cannot bypass required checks by workflow alone. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π SUCCESS METRICS | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Weekly Tracking:** | ||||||||||||||||||||||||||||||||||||
| - Average PR size: < 15 files | ||||||||||||||||||||||||||||||||||||
| - PR lifetime: < 24 hours | ||||||||||||||||||||||||||||||||||||
| - Number of scope violations: 0 | ||||||||||||||||||||||||||||||||||||
| - Merge conflicts: < 1 per week | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| **Red Flags (Auto-alert):** | ||||||||||||||||||||||||||||||||||||
| - Any PR > 50 files | ||||||||||||||||||||||||||||||||||||
| - Any branch > 48 hours old | ||||||||||||||||||||||||||||||||||||
| - Any PR title with "and", "also", "plus" | ||||||||||||||||||||||||||||||||||||
| - Any PR summary > 2 sentences (detailed descriptions in body are encouraged) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π― WHY THIS WORKS | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Psychological Benefits** | ||||||||||||||||||||||||||||||||||||
| - **Small wins**: Frequent merges build momentum | ||||||||||||||||||||||||||||||||||||
| - **Fast feedback**: Quick reviews = faster iteration | ||||||||||||||||||||||||||||||||||||
| - **Reduced risk**: Smaller changes = easier rollback | ||||||||||||||||||||||||||||||||||||
| - **Team satisfaction**: Actually shipping features | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Technical Benefits** | ||||||||||||||||||||||||||||||||||||
| - **Fewer merge conflicts**: Smaller, focused changes | ||||||||||||||||||||||||||||||||||||
| - **Easier reviews**: 50 files vs 100+ files | ||||||||||||||||||||||||||||||||||||
| - **Better testing**: Isolated changes = targeted tests | ||||||||||||||||||||||||||||||||||||
| - **Faster CI/CD**: Smaller PRs = faster pipelines | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ## π IMPLEMENTATION | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ### **Immediate Actions** | ||||||||||||||||||||||||||||||||||||
| 1. **Install pre-commit hooks**: `pre-commit install` | ||||||||||||||||||||||||||||||||||||
| 2. **Set commit template**: `git config commit.template .gitmessage.txt` | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| 2. **Set commit template**: `git config commit.template .gitmessage.txt` | |
| 2. **Set commit template**: `git config commit.template .gitmessage.txt` | |
| > **Note:** If `.gitmessage.txt` does not exist in your repository root, create it with the following recommended contents: | |
| ```txt | |
| # Commit message template | |
| # <type>(<scope>): <short summary> | |
| # | |
| # Example: | |
| # feat(api): add user authentication endpoint | |
| # | |
| # - Use imperative mood ("add", not "added"/"adds") | |
| # - Keep summary under 72 characters | |
| # - Reference issues if applicable (e.g., "Fixes #123") | |
| # | |
| # Body (optional): Explain what and why, not how. | |
| # | |
| # Footer (optional): Breaking changes, issues closed, etc. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script
scripts/check_pr_scope.pyis referenced but there's no indication whether this script exists in the repository. Consider adding a note about script availability or implementation status.