From 0916659ec3178f476e94f01ea7c3d66019c4c044 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sun, 12 May 2024 14:29:09 +0530 Subject: [PATCH 1/3] Removed unused strings in strings.en.yml Signed-off-by: Wise-Wizard --- chaoscenter/web/.husky/pre-commit | 37 ++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/chaoscenter/web/.husky/pre-commit b/chaoscenter/web/.husky/pre-commit index 8952a103b01..294ed088172 100755 --- a/chaoscenter/web/.husky/pre-commit +++ b/chaoscenter/web/.husky/pre-commit @@ -1,12 +1,43 @@ #!/bin/sh + +# Source Husky "$(dirname "$0")/_/husky.sh" MATCH_PATH='chaoscenter/web/' +STRINGS_FILE="chaoscenter/web/strings/strings.en.yaml" + +# Function to find and delete unused strings in strings.en.yaml +check_and_delete_unused_strings() { + # Create a temporary file to store the output of the inner grep command +TEMP_FILE=$(mktemp) + +# Execute the inner grep command and save the output to the temporary file +grep -rEo '\b[a-zA-Z0-9_]+\b' chaoscenter/web/**/*.js > "$TEMP_FILE" + +# Use the temporary file as input for the outer grep commands +UNUSED_STRINGS=$(grep -v '^#' "$STRINGS_FILE" | grep -vFf "$TEMP_FILE" | grep -oE '^[a-zA-Z0-9_]+') + +# Remove the temporary file +rm "$TEMP_FILE" + + + if [ -n "$UNUSED_STRINGS" ]; then + echo "Unused strings found: $UNUSED_STRINGS" + for UNUSED_STRING in $UNUSED_STRINGS; do + sed -i "/$UNUSED_STRING:/d" "$STRINGS_FILE" + done + echo "Unused strings deleted from $STRINGS_FILE" + else + echo "No unused strings found in $STRINGS_FILE" + fi +} + +check_and_delete_unused_strings BRANCH=$(git rev-parse --abbrev-ref HEAD) -if [ "$BRANCH" = "main" ]; then - echo "\033[0;31;1mYou can't commit directly to main branch\033[0m" +if [ "$BRANCH" = "master" ]; then + echo "\033[0;31;1mYou can't commit directly to master branch\033[0m" exit 1 fi @@ -24,4 +55,4 @@ if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ]; cd ./chaoscenter/web && yarn lint-staged else echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m" -fi \ No newline at end of file +fi From f76cc312d2607e070d5f4a11d6c44ba94bc612a6 Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sun, 12 May 2024 14:30:17 +0530 Subject: [PATCH 2/3] Removed unncessary changes Signed-off-by: Wise-Wizard --- chaoscenter/web/.husky/pre-commit | 8 -------- 1 file changed, 8 deletions(-) diff --git a/chaoscenter/web/.husky/pre-commit b/chaoscenter/web/.husky/pre-commit index 294ed088172..13256a31ed9 100755 --- a/chaoscenter/web/.husky/pre-commit +++ b/chaoscenter/web/.husky/pre-commit @@ -8,19 +8,11 @@ STRINGS_FILE="chaoscenter/web/strings/strings.en.yaml" # Function to find and delete unused strings in strings.en.yaml check_and_delete_unused_strings() { - # Create a temporary file to store the output of the inner grep command TEMP_FILE=$(mktemp) - -# Execute the inner grep command and save the output to the temporary file grep -rEo '\b[a-zA-Z0-9_]+\b' chaoscenter/web/**/*.js > "$TEMP_FILE" - -# Use the temporary file as input for the outer grep commands UNUSED_STRINGS=$(grep -v '^#' "$STRINGS_FILE" | grep -vFf "$TEMP_FILE" | grep -oE '^[a-zA-Z0-9_]+') - -# Remove the temporary file rm "$TEMP_FILE" - if [ -n "$UNUSED_STRINGS" ]; then echo "Unused strings found: $UNUSED_STRINGS" for UNUSED_STRING in $UNUSED_STRINGS; do From beddd5dcb621603f361f6e30d0c51d9be4ed096f Mon Sep 17 00:00:00 2001 From: Wise-Wizard Date: Sun, 12 May 2024 14:40:06 +0530 Subject: [PATCH 3/3] Removed Comments Signed-off-by: Wise-Wizard --- chaoscenter/web/.husky/pre-commit | 3 --- 1 file changed, 3 deletions(-) diff --git a/chaoscenter/web/.husky/pre-commit b/chaoscenter/web/.husky/pre-commit index 13256a31ed9..31720adb010 100755 --- a/chaoscenter/web/.husky/pre-commit +++ b/chaoscenter/web/.husky/pre-commit @@ -1,12 +1,9 @@ #!/bin/sh - -# Source Husky "$(dirname "$0")/_/husky.sh" MATCH_PATH='chaoscenter/web/' STRINGS_FILE="chaoscenter/web/strings/strings.en.yaml" -# Function to find and delete unused strings in strings.en.yaml check_and_delete_unused_strings() { TEMP_FILE=$(mktemp) grep -rEo '\b[a-zA-Z0-9_]+\b' chaoscenter/web/**/*.js > "$TEMP_FILE"