-
Notifications
You must be signed in to change notification settings - Fork 298
Automated Pre-commit Setup with Backend and Frontend Formatters #651
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds Prettier tooling and a new local Prettier pre-commit hook for frontend files, narrows Ruff/Black to the Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Developer
participant Git as Git repo
participant PreCommit as pre-commit
participant Prettier as Prettier (node)
participant RuffBlack as Ruff/Black (python)
Developer->>Git: Commit changes
Git->>PreCommit: Run configured hooks
alt Files in backend/*
PreCommit->>RuffBlack: Run Ruff/Black (filtered to backend)
RuffBlack-->>PreCommit: Lint/format result
end
alt Files in frontend/*.(ts|tsx|json)
PreCommit->>Prettier: Run local Prettier shell command (filenames passed)
Prettier-->>PreCommit: Format result / exit status
end
PreCommit-->>Git: Allow or block commit based on hook results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
package.json (1)
9-9: Remove the husky prepare script.The
preparescript on line 9 referenceshusky, which has been removed from devDependencies. This will causenpm installto fail."linux-dev": "bash ./scripts/linux-dev.sh", "win-dev": "cd scripts && win-dev.bat", - "prepare": "husky", "lint:check": "cd frontend && eslint --max-warnings 0 --config .eslintrc.json .",
🧹 Nitpick comments (3)
.pre-commit-config.yaml (1)
23-23: Simplify the path manipulation logic.The current bash command uses
sedto stripfrontend/from all filenames, which could be fragile with edge cases (e.g., paths containing multiplefrontend/segments or special characters). Consider a more robust approach:- entry: bash -c 'FILES=$(echo "$@" | sed "s|frontend/||g") && cd frontend && npx prettier --write $FILES' -- + entry: bash -c 'cd frontend && npx prettier --write "${@#frontend/}"' --Or for even better handling of multiple files:
- entry: bash -c 'FILES=$(echo "$@" | sed "s|frontend/||g") && cd frontend && npx prettier --write $FILES' -- + entry: bash -c 'cd frontend && for f in "$@"; do npx prettier --write "${f#frontend/}"; done' --scripts/setup.sh (1)
167-167: Clarify the success message.The message "Node pre-commit installation finished successfully" is misleading since this section installs both Python pre-commit and Node.js formatting tools (Prettier).
-echo "Node pre-commit installation finished successfully." +echo "Pre-commit hooks and formatting tools installed successfully."scripts/setup.ps1 (1)
152-161: Remove duplicate comment block.Lines 153-159 duplicate lines 160-161. Remove the redundant comments for clarity.
- -# ------------------------- -# NODE-BASED pre-commit installer (global hook in package.json) -# Behavior: -# - if package.json contains "pre-commit" key, we assume the repo uses Node pre-commit. -# - install local dev deps (idempotent), then run npx pre-commit install -# ------------------------- # ------------------------- # NODE-BASED pre-commit installer (global hook in package.json) # -------------------------
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
.pre-commit-config.yaml(1 hunks)package.json(1 hunks)scripts/setup.ps1(1 hunks)scripts/setup.sh(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Backend Tests
| - repo: https://github.com/charliermarsh/ruff-pre-commit | ||
| rev: "v0.0.241" |
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.
🧩 Analysis chain
Verify the Ruff version is current.
The Ruff version v0.0.241 appears outdated (from early 2023). Ensure this is the intended version and consider updating to a more recent release for bug fixes and new features.
🌐 Web query:
What is the latest stable version of ruff-pre-commit?
💡 Result:
The latest stable version is v0.14.5 (released Nov 13, 2025). [1][2]
Sources:
[1] GitHub Releases — astral-sh/ruff-pre-commit (v0.14.5).
[2] ruff-pre-commit README (example rev: v0.14.5).
Update Ruff to the latest stable version.
The latest stable version of ruff-pre-commit is v0.14.5 (released Nov 13, 2025), while the current version in this file is v0.0.241. Update rev to "v0.14.5" to get the latest bug fixes and features.
🤖 Prompt for AI Agents
.pre-commit-config.yaml around lines 3 to 4: the ruff-pre-commit hook is pinned
to an old rev "v0.0.241"; update the rev value to the latest stable tag
"v0.14.5" so the hook uses the current ruff release.
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
scripts/setup.sh (1)
156-157: Consider verifying npm availability before use.The script installs Node.js earlier (lines 116-127) but doesn't verify npm is available before running
npm install. While unlikely to fail, adding a check would make the script more robust.echo "Installing Prettier for frontend..." +if ! command -v npm &> /dev/null; then + echo -e "${RED}npm is not available. Please check Node.js installation.${NC}" + exit 1 +fi npm install --save-dev prettier prettier-plugin-tailwindcss --no-audit --no-fundscripts/setup.ps1 (2)
153-161: Remove duplicate comment block.Lines 153-158 and 159-161 contain duplicate comment blocks describing the NODE-BASED pre-commit installer. The second block (lines 159-161) should be removed to avoid redundancy.
-# ------------------------- -# NODE-BASED pre-commit installer (global hook in package.json) -# Behavior: -# - if package.json contains "pre-commit" key, we assume the repo uses Node pre-commit. -# - install local dev deps (idempotent), then run npx pre-commit install -# ------------------------- # ------------------------- # NODE-BASED pre-commit installer (global hook in package.json) # -------------------------
179-180: Usepython -m pipfor more reliable package installation.Line 180 uses
pipdirectly without verification. Since Python is installed earlier in the script, usingpython -m pipwould be more reliable and consistent.# Install dev dependencies (idempotent) npm install --save-dev prettier prettier-plugin-tailwindcss --no-audit --no-fund -pip install pre-commit +python -m pip install --user pre-commit
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
scripts/setup.ps1(1 hunks)scripts/setup.sh(1 hunks)
🔇 Additional comments (4)
scripts/setup.sh (2)
159-160: LGTM! Good error handling for git config reset.The git config reset with error suppression (
2>/dev/null) is appropriate, ensuring a clean state before installing pre-commit hooks without failing if the config doesn't exist.
162-164: LGTM! Correct pre-commit installation sequence.The sequence of
pre-commit cleanfollowed bypre-commit installis correct and will properly set up the git hooks, assuming pre-commit was installed successfully.scripts/setup.ps1 (2)
181-183: LGTM! Correct pre-commit setup sequence.The git hooks reset followed by
pre-commit cleanandpre-commit installis the correct sequence for setting up pre-commit hooks.
186-191: LGTM! Proper error handling and cleanup.The try-catch-finally structure with the location reset in the finally block ensures the script returns to the correct directory even if errors occur, which is good practice for PowerShell scripts.
| echo "Installing Python pre-commit and hook dependencies..." | ||
| sudo apt-get update | ||
| sudo apt-get install -y python3 python3-pip | ||
|
|
||
| sudo pip install pre-commit |
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.
Add OS-specific conditional logic for package installation.
Lines 151-152 use apt-get which only works on Debian-based systems, but this script supports macOS (detected at lines 27-69). This block will fail on macOS.
Consider adding OS-conditional logic similar to the dependency installation block at the top of the script:
echo "Installing Python pre-commit and hook dependencies..."
-sudo apt-get update
-sudo apt-get install -y python3 python3-pip
+if [ -f "/etc/debian_version" ]; then
+ sudo apt-get update
+ sudo apt-get install -y python3 python3-pip
+elif [[ "$(uname)" == "Darwin" ]]; then
+ # Python3 and pip should already be available via pyenv setup
+ echo "Using Python from pyenv..."
+fi
-sudo pip install pre-commit
+python3 -m pip install --user pre-commitAdditionally, replace sudo pip with python3 -m pip install --user to follow Python packaging best practices and avoid system-wide pip usage with elevated privileges.
🤖 Prompt for AI Agents
In scripts/setup.sh around lines 150 to 154, the script uses apt-get and sudo
pip which fail on non-Debian systems and unnecessarily use system-wide pip;
update this block to perform OS detection (reuse the existing macOS vs Linux
logic used earlier), run apt-get install only on Debian/Ubuntu, use the macOS
path to install Python tooling (e.g., brew install or skip if already handled),
and replace sudo pip install pre-commit with python3 -m pip install --user
pre-commit so pip installs into the user environment; ensure commands are
guarded by conditional branches and that exit codes are handled as in the
earlier dependency-install block.
This pull request introduces improvements to the project's code formatting and pre-commit hook setup for both Python and frontend code. It adds configuration for Python formatters and linters, sets up Prettier for frontend files, and updates the installation scripts to ensure all necessary dependencies and hooks are installed automatically.
Pre-commit hook and code formatting setup:
ruff) and formatters (black) to.pre-commit-config.yaml, targeting thebackend/directory..ts,.tsx,.json) in.pre-commit-config.yaml.Dependency management:
prettierandprettier-plugin-tailwindcssas development dependencies inpackage.jsonfor frontend formatting.Setup script enhancements:
scripts/setup.ps1to install Python and Node pre-commit dependencies, configure git hooks, and run pre-commit installation ifpackage.jsonis present.scripts/setup.shto install Python and Node pre-commit dependencies, reset git hooks, and install pre-commit hooks for both Python and frontend code.Summary by CodeRabbit