diff --git a/scripts/validate-eslint.sh b/scripts/validate-eslint.sh index 01ccc7e..756ea09 100755 --- a/scripts/validate-eslint.sh +++ b/scripts/validate-eslint.sh @@ -1,14 +1,12 @@ -#!/usr/bin/env bash +#!/bin/sh # CREDITS: https://gist.github.com/linhmtran168/2286aeafe747e78f53bf # MODIFIED: t.hamoudi -# Get staged JS/TS/Vue files as an array -readarray -t STAGED_FILES < <(git diff --cached --name-only --diff-filter=ACM | grep -E "(.js$|.jsx$|.ts$|.tsx$|.vue$)") +# Get staged JS/TS/Vue files +STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E "(.js$|.jsx$|.ts$|.tsx$|.vue$)") -echo -e "Found ${#STAGED_FILES[@]} staged files." - -if [[ ${#STAGED_FILES[@]} -eq 0 ]]; then +if [ -z "$STAGED_FILES" ]; then echo "No staged files found, exiting..." exit 0 fi @@ -29,10 +27,10 @@ fi # Check for local eslint installation if [ -f "node_modules/.bin/eslint" ]; then ESLINT="./node_modules/.bin/eslint" - echo -e "Starting ESLint validation..." - echo -e "\e[1;32mA valid ESlint installation found at $ESLINT\e[0m" + echo "Starting ESLint validation..." + echo "A valid ESLint installation found at $ESLINT" else - echo -e "\e[1;31mNo valid ESlint installation found. Please install ESLint by running: "$INSTALL_CMD"\e[0m" + echo "No valid ESLint installation found. Please install ESLint by running: $INSTALL_CMD" exit 1 fi @@ -41,23 +39,27 @@ if [ -f "eslint.config.js" ] || [ -f "eslint.config.mjs" ] || [ -f "eslint.confi [ -f "eslint.config.ts" ] || [ -f "eslint.config.mts" ] || [ -f "eslint.config.cts" ] || \ [ -f ".eslintrc.js" ] || [ -f ".eslintrc.cjs" ] || [ -f ".eslintrc.json" ] || \ [ -f ".eslintrc.yml" ] || [ -f ".eslintrc.yaml" ] || [ -f ".eslintrc" ]; then - echo -e "\e[1;32mA valid ESLint configuration file was found.\e[0m" + echo "A valid ESLint configuration file was found." else - echo -e "\e[1;31mNo valid ESLint configuration file found. Please initialize your configuration by running: "$ESLINT" --init\e[0m" + echo "No valid ESLint configuration file found. Please initialize your configuration by running: $ESLINT --init" exit 1 fi -for FILE in "${STAGED_FILES[@]}"; do - echo "Checking file: $FILE" - "$ESLINT" "$FILE" +# Process each file +echo "$STAGED_FILES" | while IFS= read -r FILE; do + if [ -n "$FILE" ]; then + echo "Checking file: $FILE" + "$ESLINT" "$FILE" - if [[ "$?" == 0 ]]; then - echo -e "\e[1;32m $FILE passed.\e[0m" - else - echo -e "\e[1;31m$FILE failed.\e[0m" - echo -e "\e[1;31mCOMMIT FAILED: Your commit contains files that did not pass linting. Please fix the issues and try again.\e[0m" - exit 1 + if [ "$?" -eq 0 ]; then + echo "$FILE passed." + else + echo "$FILE failed." + echo "COMMIT FAILED: Your commit contains files that did not pass linting. Please fix the issues and try again." + exit 1 + fi fi done -echo -e "\e[1;32mCOMMIT SUCCEEDED\e[0m" + +echo "COMMIT SUCCEEDED" exit 0