Forráskód Böngészése

CDPD-65912: [git] precommit hooks for linting

Change-Id: I1254867065619ef5a8627b418fc27b1e18ab3216
tabraiz 1 éve
szülő
commit
f5250cd751
2 módosított fájl, 27 hozzáadás és 1 törlés
  1. 19 0
      setup-hooks.sh
  2. 8 1
      tools/git-hooks/pre-commit

+ 19 - 0
setup-hooks.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Source path of the precommit hook
+SOURCE_HOOK="tools/git-hooks/pre-commit"
+
+# Destination path of the pre-commit hook
+DEST_HOOK=".git/hooks/pre-commit"
+
+# Copy the precommit hook to .git/hooks directory
+cp "$SOURCE_HOOK" "$DEST_HOOK"
+
+# Make the pre-commit hook executable
+chmod +x "$DEST_HOOK"
+
+# Install ESLint and related dependencies
+npm install eslint -g
+
+echo "ESLint and related dependencies installed."
+echo "Pre-commit hook copied and made executable successfully!"

+ 8 - 1
tools/git-hooks/pre-commit

@@ -19,7 +19,7 @@
 set -e
 ERRORS=false
 
-for FILE in `git diff --name-only` ; do
+for FILE in `git diff --cached --name-only` ; do
     if [[ "$FILE" =~ ^.+(py)$ ]]; then
         if [ "grep 'distinct()' $FILE" ]; then  # HUE-3191: Check if distinct() exists in any Python files
             ERRORS=true
@@ -30,6 +30,13 @@ for FILE in `git diff --name-only` ; do
             ERRORS=true
             echo -e "[ERROR] $FILE: Found pdb.set_trace() debug statements in file.\n"
         fi
+    elif [[ "$FILE" =~ ^.+(js|jsx|ts|tsx)$ ]]; then
+        echo "Running ESLint for $FILE..."
+        eslint "$FILE"  # Run ESLint for JavaScript/JSX files
+        if [ $? -ne 0 ]; then
+            ERRORS=true
+            echo -e "[ERROR] ESLint found issues in $FILE.\n"
+        fi
     fi
 done