From 26c91451dfe99c4550a325448bd5085eb1af20f2 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Wed, 24 Apr 2024 00:41:55 +0530 Subject: [PATCH 1/2] updated pre-commit.sh to check for unused strings in strings.en.yaml Signed-off-by: shruti2522 --- chaoscenter/web/.husky/pre-commit | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/chaoscenter/web/.husky/pre-commit b/chaoscenter/web/.husky/pre-commit index 8952a103b01..aa704ef95bd 100755 --- a/chaoscenter/web/.husky/pre-commit +++ b/chaoscenter/web/.husky/pre-commit @@ -1,8 +1,9 @@ #!/bin/sh "$(dirname "$0")/_/husky.sh" -MATCH_PATH='chaoscenter/web/' +echo "\033[0;31;1mYou can't commit directly to main branch\033[0m" +MATCH_PATH='chaoscenter/web/' BRANCH=$(git rev-parse --abbrev-ref HEAD) if [ "$BRANCH" = "main" ]; then @@ -16,12 +17,20 @@ if expr "$BRANCH" : 'release\/.*' >/dev/null; then fi LITMUS_UI_FILE_CHANGES=$(git diff --name-only --cached | grep "$MATCH_PATH" -c) - echo "\033[0;93mLITMUS_UI_FILE_CHANGES\033[0m ⟶ $LITMUS_UI_FILE_CHANGES" -if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ]; - then - 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 +if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ]; then + cd ./chaoscenter/web && yarn lint-staged +else + echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m" +fi + +# check for unused strings in strings.en.yaml +UNUSED_STRINGS=$(grep -Fvxf <(grep -oP '"\K[^"]+' ./chaoscenter/web/strings/strings.en.yaml) <(grep -rl 'chaoscenter/web/src' ./*)) +if [ "$UNUSED_STRINGS" != "" ]; then + echo "\033[0;31;1mERROR: Unused strings found in strings.en.yaml\033[0m" + echo "$UNUSED_STRINGS" + exit 1 +fi + +exit 0 From 40cf4c69d6cea4f53fac3e73dc6267cbb8421475 Mon Sep 17 00:00:00 2001 From: shruti2522 Date: Sat, 27 Apr 2024 03:10:32 +0530 Subject: [PATCH 2/2] updated pre-commit.sh Signed-off-by: shruti2522 --- chaoscenter/web/.husky/pre-commit | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/chaoscenter/web/.husky/pre-commit b/chaoscenter/web/.husky/pre-commit index aa704ef95bd..dc542f56434 100755 --- a/chaoscenter/web/.husky/pre-commit +++ b/chaoscenter/web/.husky/pre-commit @@ -1,9 +1,8 @@ #!/bin/sh "$(dirname "$0")/_/husky.sh" -echo "\033[0;31;1mYou can't commit directly to main branch\033[0m" - MATCH_PATH='chaoscenter/web/' + BRANCH=$(git rev-parse --abbrev-ref HEAD) if [ "$BRANCH" = "main" ]; then @@ -17,20 +16,22 @@ if expr "$BRANCH" : 'release\/.*' >/dev/null; then fi LITMUS_UI_FILE_CHANGES=$(git diff --name-only --cached | grep "$MATCH_PATH" -c) + echo "\033[0;93mLITMUS_UI_FILE_CHANGES\033[0m ⟶ $LITMUS_UI_FILE_CHANGES" -if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ]; then - cd ./chaoscenter/web && yarn lint-staged -else - echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m" +if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ]; + then + cd ./chaoscenter/web && yarn lint-staged + else + echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m" fi # check for unused strings in strings.en.yaml -UNUSED_STRINGS=$(grep -Fvxf <(grep -oP '"\K[^"]+' ./chaoscenter/web/strings/strings.en.yaml) <(grep -rl 'chaoscenter/web/src' ./*)) +UNUSED_STRINGS=$(grep -Fvxf <(grep -oP '"\K[^"]+' chaoscenter/web/strings/strings.en.yaml) <(grep -rl 'chaoscenter/web/src' ./*)) if [ "$UNUSED_STRINGS" != "" ]; then echo "\033[0;31;1mERROR: Unused strings found in strings.en.yaml\033[0m" echo "$UNUSED_STRINGS" exit 1 fi -exit 0 +