Skip to content

Commit

Permalink
Update linting hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mutugiii committed Oct 16, 2024
1 parent ffd6f19 commit 2d03f13
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions git-hooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ output_result() {
message=$2
output=$3

if [ $ret_code != 0 ]; then
if [ $ret_code -ne 0 ]; then
printf "${RED}${message} failed.${NC}\n"
echo "$output"
pass=false
Expand All @@ -45,23 +45,39 @@ output_result() {
# Get number of uncommitted changes
CHANGES=$(git diff --numstat | wc -l)
CHANGES_CACHED=$(git diff --cached --numstat | wc -l)
TOTAL_CHANGES=$(($CHANGES + $CHANGES_CACHED))
TOTAL_CHANGES=$((CHANGES + CHANGES_CACHED))

# Stash all uncommitted changes before running tests
git stash -k

# Check if vagrant is running
vagrant_status=$(vagrant status dev --machine-readable | grep state,running)

# Function to run linting for a given project
run_lint() {
local project_dir=$1
local lint_name=$2

if [ -z "$vagrant_status" ]; then
# If Vagrant is not running, run lint locally
lint_output=$(cd "$project_dir" && npm run lint 2>&1)
ret_code_lint=$?
else
# If Vagrant is running, run lint inside the Vagrant machine
lint_output=$(vagrant ssh dev -- -t "cd /vagrant/$project_dir && npm run lint" 2>&1)
ret_code_lint=$?
fi

output_result $ret_code_lint "$lint_name" "$lint_output"
}

echo "Running Linters:"
if [ "$vagrant_status" = "" ]; then
tslint=$(npm run lint)
else
tslint=$(vagrant ssh dev -- -t 'cd /vagrant;npm run lint')
fi

ret_code_tslint=$?
output_result $ret_code_tslint "tslint" $tslint
# Run linting for the main project
run_lint "." "Main project lint"

# Run linting for the chatapi project
run_lint "chatapi" "chatapi lint"

# If we stashed changes earlier, pop them back off the stack
if [ $TOTAL_CHANGES -ne "0" ]
Expand Down

0 comments on commit 2d03f13

Please sign in to comment.