Skip to content

Conversation

@Hemil36
Copy link
Contributor

@Hemil36 Hemil36 commented Nov 17, 2025

  • Fixes : Feat: Add Automatic Local Linting on Commit #613
    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:

  • Added configuration for Python linters (ruff) and formatters (black) to .pre-commit-config.yaml, targeting the backend/ directory.
  • Added a custom Prettier hook for frontend files (.ts, .tsx, .json) in .pre-commit-config.yaml.

Dependency management:

  • Added prettier and prettier-plugin-tailwindcss as development dependencies in package.json for frontend formatting.

Setup script enhancements:

  • Updated scripts/setup.ps1 to install Python and Node pre-commit dependencies, configure git hooks, and run pre-commit installation if package.json is present.
  • Updated scripts/setup.sh to install Python and Node pre-commit dependencies, reset git hooks, and install pre-commit hooks for both Python and frontend code.

Summary by CodeRabbit

  • Chores
    • Added automated pre-commit formatting for frontend files using Prettier (with Tailwind plugin).
    • Restricted backend formatting hooks to backend files to reduce unnecessary checks.
    • Updated setup scripts to auto-install and configure Node and Python pre-commit tooling across platforms.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

Adds Prettier tooling and a new local Prettier pre-commit hook for frontend files, narrows Ruff/Black to the backend path, and updates Windows and Unix setup scripts to install Node/Python pre-commit dependencies and initialize pre-commit hooks.

Changes

Cohort / File(s) Summary
Pre-commit configuration
.pre-commit-config.yaml
Adds file filtering (include: backend/.*) to Ruff and Black hooks; adds a local Prettier hook that runs a shell command to format frontend files (TS/TSX/JSON) and uses filename passing.
Development dependencies
package.json
Removes husky devDependency; adds prettier (^3.6.2) and prettier-plugin-tailwindcss (^0.7.1) to devDependencies.
Setup automation (Windows)
scripts/setup.ps1
Appends a Node-based pre-commit installer: installs Node dev dependencies (prettier, plugin), installs Python pre-commit, runs pre-commit install, resets git hooks where needed, and restores working directory; includes try/catch/finally control flow.
Setup automation (Unix)
scripts/setup.sh
Appends steps to install Python pre-commit and hook deps, install Prettier for frontend, reset git hooks, and run pre-commit install with a success message.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Check .pre-commit-config.yaml hook definitions and files/types globs for correctness and cross-platform shell invocation.
  • Verify package.json devDependencies and that removing husky won't leave orphaned config.
  • Validate scripts/setup.ps1 and scripts/setup.sh for idempotence, error handling, correct working-directory restoration, and consistent behavior across platforms.

Poem

🐰 I nibbled lines and found a tune,

Husky hopped, Prettier came soon.
Frontend gleams in tidy rows,
Backend guards where Ruff now goes.
Hooray — commits neat as a moon. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: automated pre-commit setup with formatters for both backend (Ruff, Black) and frontend (Prettier).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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

@github-actions github-actions bot added the bug Something isn't working label Nov 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 prepare script on line 9 references husky, which has been removed from devDependencies. This will cause npm install to 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 sed to strip frontend/ from all filenames, which could be fragile with edge cases (e.g., paths containing multiple frontend/ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8dbc960 and 69236e8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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

Comment on lines 3 to 4
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.241"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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-fund
scripts/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: Use python -m pip for more reliable package installation.

Line 180 uses pip directly without verification. Since Python is installed earlier in the script, using python -m pip would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 69236e8 and 083d68b.

📒 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 clean followed by pre-commit install is 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 clean and pre-commit install is 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.

Comment on lines +150 to +154
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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-commit

Additionally, 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.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Add Automatic Local Linting on Commit

1 participant