Add Pre Commit Check (#4642)
* Removed unused strings in strings.en.yml Signed-off-by: Wise-Wizard <saransh.shankar@gmail.com> * Removed unncessary changes Signed-off-by: Wise-Wizard <saransh.shankar@gmail.com> * Removed Comments Signed-off-by: Wise-Wizard <saransh.shankar@gmail.com> --------- Signed-off-by: Wise-Wizard <saransh.shankar@gmail.com> Co-authored-by: Namkyu Park <53862866+namkyu1999@users.noreply.github.com> Co-authored-by: Sayan Mondal <sayan.mondal@harness.io>
This commit is contained in:
parent
14c9808302
commit
dcc7f60b7e
|
@ -2,11 +2,31 @@
|
||||||
"$(dirname "$0")/_/husky.sh"
|
"$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
MATCH_PATH='chaoscenter/web/'
|
MATCH_PATH='chaoscenter/web/'
|
||||||
|
STRINGS_FILE="chaoscenter/web/strings/strings.en.yaml"
|
||||||
|
|
||||||
|
check_and_delete_unused_strings() {
|
||||||
|
TEMP_FILE=$(mktemp)
|
||||||
|
grep -rEo '\b[a-zA-Z0-9_]+\b' chaoscenter/web/**/*.js > "$TEMP_FILE"
|
||||||
|
UNUSED_STRINGS=$(grep -v '^#' "$STRINGS_FILE" | grep -vFf "$TEMP_FILE" | grep -oE '^[a-zA-Z0-9_]+')
|
||||||
|
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)
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
if [ "$BRANCH" = "main" ]; then
|
if [ "$BRANCH" = "master" ]; then
|
||||||
echo "\033[0;31;1mYou can't commit directly to main branch\033[0m"
|
echo "\033[0;31;1mYou can't commit directly to master branch\033[0m"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -24,4 +44,4 @@ if [ "$LITMUS_UI_FILE_CHANGES" -gt 0 ];
|
||||||
cd ./chaoscenter/web && yarn lint-staged
|
cd ./chaoscenter/web && yarn lint-staged
|
||||||
else
|
else
|
||||||
echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m"
|
echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue