From 46db1fb9b479692e939f7a746f2653d55619d541 Mon Sep 17 00:00:00 2001 From: JC Franco Date: Thu, 12 Sep 2024 09:44:12 -0700 Subject: [PATCH 1/3] chore(icons): ensure UI icons follow naming convention --- .husky/pre-commit | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 9c3f1a2ac0f..c1cb5367c19 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,11 +1,49 @@ #!/usr/bin/env sh -lint-staged - -types_path="packages/calcite-components/src/components.d.ts" +ensure_types_are_up_to_date() { + types_path="packages/calcite-components/src/components.d.ts" -# make sure the types are always up to date -if [ -n "$(git diff --name-only -- "$types_path")" ]; then + if [ -n "$(git diff --name-only -- "$types_path")" ]; then echo "Automatically staging changes to \"$types_path\"" git add "$types_path" -fi + fi +} + +check_ui_icon_name_consistency() { + SVG_ICON_DIR="packages/calcite-ui-icons/icons" + + # this pattern checks for `-.svg` or `--f.svg` for filled icons + # where `` is kebab-case, `` is 16, 24, or 32 + valid_pattern="^[a-z0-9-]+-(16|24|32)(-f)?\\.svg$" + + # this pattern will check for invalid use of "-f-" anywhere except right before the size + invalid_pattern="-[a-z0-9]+-f-" + + STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) + + for file in $STAGED_FILES; do + if [[ $file == "$SVG_ICON_DIR"* ]]; then + if [[ $file == *.svg ]]; then + filename=$(basename "$file") + + # first, ensure the filename follows the valid pattern + if ! [[ $filename =~ $valid_pattern ]]; then + echo "Error: File '$file' does not follow the naming convention (-.svg or --f.svg)." + exit 1 + fi + + # then, ensure there's no invalid use of "-f-" anywhere except right before the size + if [[ $filename =~ $invalid_pattern ]]; then + echo "Error: File '$file' has an invalid '-f-' and does not follow the naming convention (-.svg or --f.svg)." + exit 1 + fi + fi + fi + done +} + +lint-staged +ensure_types_are_up_to_date +check_ui_icon_name_consistency + +exit 0 From 7ea0f98703b34720d244498a0f89963675db1fd5 Mon Sep 17 00:00:00 2001 From: JC Franco Date: Thu, 12 Sep 2024 15:46:50 -0700 Subject: [PATCH 2/3] ensure const names are consistent --- .husky/pre-commit | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index c1cb5367c19..9db0909bc60 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -10,7 +10,7 @@ ensure_types_are_up_to_date() { } check_ui_icon_name_consistency() { - SVG_ICON_DIR="packages/calcite-ui-icons/icons" + svg_icon_dir="packages/calcite-ui-icons/icons" # this pattern checks for `-.svg` or `--f.svg` for filled icons # where `` is kebab-case, `` is 16, 24, or 32 @@ -19,10 +19,10 @@ check_ui_icon_name_consistency() { # this pattern will check for invalid use of "-f-" anywhere except right before the size invalid_pattern="-[a-z0-9]+-f-" - STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM) + staged_files=$(git diff --cached --name-only --diff-filter=ACM) - for file in $STAGED_FILES; do - if [[ $file == "$SVG_ICON_DIR"* ]]; then + for file in $staged_files; do + if [[ $file == "$svg_icon_dir"* ]]; then if [[ $file == *.svg ]]; then filename=$(basename "$file") From 83278372bd1a226a8fe83da5201702a5a587c176 Mon Sep 17 00:00:00 2001 From: JC Franco Date: Fri, 13 Sep 2024 01:09:35 -0700 Subject: [PATCH 3/3] add quotes to variables --- .husky/pre-commit | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 9db0909bc60..9cf36f8fa8f 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -19,21 +19,21 @@ check_ui_icon_name_consistency() { # this pattern will check for invalid use of "-f-" anywhere except right before the size invalid_pattern="-[a-z0-9]+-f-" - staged_files=$(git diff --cached --name-only --diff-filter=ACM) + staged_files="$(git diff --cached --name-only --diff-filter=ACM)" for file in $staged_files; do - if [[ $file == "$svg_icon_dir"* ]]; then - if [[ $file == *.svg ]]; then - filename=$(basename "$file") + if [[ "$file" == "$svg_icon_dir"* ]]; then + if [[ "$file" == *.svg ]]; then + filename="$(basename "$file")" # first, ensure the filename follows the valid pattern - if ! [[ $filename =~ $valid_pattern ]]; then + if ! [[ "$filename" =~ $valid_pattern ]]; then echo "Error: File '$file' does not follow the naming convention (-.svg or --f.svg)." exit 1 fi # then, ensure there's no invalid use of "-f-" anywhere except right before the size - if [[ $filename =~ $invalid_pattern ]]; then + if [[ "$filename" =~ $invalid_pattern ]]; then echo "Error: File '$file' has an invalid '-f-' and does not follow the naming convention (-.svg or --f.svg)." exit 1 fi