Skip to content

Commit

Permalink
Merge pull request #217 from PublicisSapient/201_husky_pre_commit
Browse files Browse the repository at this point in the history
Implemented Husky Pre-commit hook to run lint and test before committing
  • Loading branch information
zoltan-dulac authored Aug 28, 2024
2 parents c7111fd + d241799 commit 6b0ff4c
Show file tree
Hide file tree
Showing 3 changed files with 565 additions and 15 deletions.
15 changes: 6 additions & 9 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

. "$(dirname "$0")/_/husky.sh"

# This is the code that automatically runs the Prettier formatter on all staged parts of files that are to be committed. It is run after a commit has been triggered, but before the commit is actually made. This ensures that all code that is committed is formatted correctly.
# Check if NODE_ENV is set to production
if [ "$NODE_ENV" = "production" ] || [ "$CI" = "true" ]; then
echo "Skipping pre-commit hook in production environment"
exit 0
fi

# Source: https://prettier.io/docs/en/precommit.html#option-4-git-format-stagedhttpsgithubcomhallettjgit-format-staged

npx git-format-staged -f 'prettier --ignore-unknown --stdin-filepath "{}"' '*.js' '*.jsx' '*.less' '*.md' '*.json' '*.html' '*.php' '*.sh'

# If you have issues when running the npx command in an IDE, you should try running the command in the terminal instead. This issue is due to the PATH values not being set as expected in the IDE in order for npx to be recognized. See https://stackoverflow.com/questions/67115897/vscode-github-desktop-pre-commit-hook-npx-command-not-found for more information.

# Run eslint
npm run eslint && npm run stylelint
npx lint-staged
Loading

0 comments on commit 6b0ff4c

Please sign in to comment.