Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(icons): ensure UI icons follow naming convention #10292

Merged
merged 3 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -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 `<iconName>-<size>.svg` or `<iconName>-<size>-f.svg` for filled icons
# where `<iconName>` is kebab-case, `<size>` 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 (<iconName>-<size>.svg or <iconName>-<size>-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 (<iconName>-<size>.svg or <iconName>-<size>-f.svg)."
exit 1
fi
fi
fi
done
}

lint-staged
ensure_types_are_up_to_date
check_ui_icon_name_consistency

exit 0
Loading