-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add pre-commit hook using husky for linting and formatting #281
Conversation
WalkthroughThis update integrates Husky to automate linting and formatting checks before commits in both frontend and backend directories. New scripts were added to the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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: 2
Outside diff range, codebase verification and nitpick comments (4)
.husky/pre-commit (2)
1-2
: Consider usinggit diff --cached --name-only --diff-filter=d
.The current command lists all changed files, including deleted ones. Using
--diff-filter=d
will exclude deleted files, which can prevent unnecessary checks.- CHANGED_FILES=$(git diff --cached --name-only) + CHANGED_FILES=$(git diff --cached --name-only --diff-filter=d)
27-29
: Ensure consistent use of format check commands in pre-commit script.The backend's pre-commit script uses
npm run format
, while both the frontend and backendpackage.json
files defineformat:check
for checking formatting. Update the pre-commit script to usenpm run format:check
for consistency.
- Update
.husky/pre-commit
to usenpm run format:check
instead ofnpm run format
.Analysis chain
Ensure consistent formatting check command.
The backend uses
npm run format
, while the frontend usesnpm run format:check
. Ensure consistency in the commands if both should perform a check.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that both frontend and backend use consistent format check commands. # Test: Search for format commands in package.json files. Expect: Consistent format check commands. rg --type json '"format":' --files-with-matches --glob '!node_modules/**'Length of output: 118
Script:
#!/bin/bash # Extract format-related scripts from frontend/package.json and backend/package.json # Extract scripts from frontend/package.json jq '.scripts | to_entries[] | select(.key | test("format"))' frontend/package.json # Extract scripts from backend/package.json jq '.scripts | to_entries[] | select(.key | test("format"))' backend/package.jsonLength of output: 462
frontend/package.json (1)
7-7
: **The.hussey
directory is missing in the expected location.**sThe
prepare
script infrontend/package.json
expects the.hussey
directory to be one level above the current directory. However, this directory is missing. Please verify the directory structure or update the script to ensure Hussey hooks are set up correctly.
- Review the location of the
.hussey
directory.- Update the
prepare
script or move the.hussey
directory to the correct location.Analysis chain
Ensure the
prepare
script path is correct.The script
cd .. && husky .husky
assumes the.husky
directory is in the parent directory. Verify this path is correct.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the presence of the `.husky` directory in the parent directory. # Test: Check if the `.husky` directory exists in the parent directory. Expect: Directory exists. [ -d "../.husky" ] && echo ".husky directory exists" || echo ".husky directory missing"Length of output: 81
backend/package.json (1)
9-9
: The.husky
directory is missing in the expected location.The
prepare
script inbackend/package.json
assumes the.husky
directory is in the parent directory, but it was not found there. Please verify the correct path or ensure the directory is present.
- Line 9 in
backend/package.json
:"prepare": "cd .. && husky .husky"
Analysis chain
Ensure the
prepare
script path is correct.The script
cd .. && husky .husky
assumes the.husky
directory is in the parent directory. Verify this path is correct.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the presence of the `.husky` directory in the parent directory. # Test: Check if the `.husky` directory exists in the parent directory. Expect: Directory exists. [ -d "../.husky" ] && echo ".husky directory exists" || echo ".husky directory missing"Length of output: 81
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (2)
backend/package-lock.json
is excluded by!**/package-lock.json
frontend/package-lock.json
is excluded by!**/package-lock.json
Files selected for processing (3)
- .husky/pre-commit (1 hunks)
- backend/package.json (1 hunks)
- frontend/package.json (2 hunks)
Additional comments not posted (2)
frontend/package.json (1)
87-87
: Husky dependency added correctly.The addition of Husky as a dev dependency is correct and aligns with the PR objectives.
backend/package.json (1)
62-62
: Husky dependency added correctly.The addition of Husky as a dev dependency is correct and aligns with the PR objectives.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- .husky/pre-commit (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- .husky/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.
I have a question.
I remember the context we discussed on Discord last time. However, if we're going to set up pre-commit
, wouldn't it be better to use lint-staged
?
This way, we can limit the checks to only staged files, and Lint checks won't be performed on simple document edits like md
files.
@gwbaik9717 How do you think about this?
Absolutely! There doesn't seem to be any downside or side-effects to adding |
@devleejb @gwbaik9717 |
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- .husky/pre-commit (1 hunks)
- backend/package.json (1 hunks)
- frontend/package.json (2 hunks)
Files skipped from review as they are similar to previous changes (3)
- .husky/pre-commit
- backend/package.json
- frontend/package.json
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- .husky/pre-commit (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- .husky/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.
Thank you for your contribution.
* Add pre-commit hook for linting and formatting * Separate checking command failures * Change to lint-staged for pre-commit hook * Clearly revise the error message
What this PR does / why we need it?
This PR adds a pre-commit hook script using Husky to automatically lint and format code changes in the frontend and backend directories before each commit. The commit will be aborted if any linting or formatting errors are detected, which helps maintain code consistency and quality throughout the codebase.
Any background context you want to provide?
Previously, the codebase did not have a pre-commit hook to enforce linting and formatting checks before commit, leading to inconsistencies and potential errors in the code.
What are the relevant tickets?
Fixes #276
Checklist
Summary by CodeRabbit
New Features
Chores