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 1 commit
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)
jcfranco marked this conversation as resolved.
Show resolved Hide resolved

for file in $STAGED_FILES; do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for file in $STAGED_FILES; do
for file in "$STAGED_FILES"; do

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoting this one gives me the following error:

Since you double quoted this, it will not word split, and the loop will only run once.

if [[ $file == "$SVG_ICON_DIR"* ]]; then
jcfranco marked this conversation as resolved.
Show resolved Hide resolved
if [[ $file == *.svg ]]; then
jcfranco marked this conversation as resolved.
Show resolved Hide resolved
filename=$(basename "$file")
jcfranco marked this conversation as resolved.
Show resolved Hide resolved

# first, ensure the filename follows the valid pattern
if ! [[ $filename =~ $valid_pattern ]]; then
jcfranco marked this conversation as resolved.
Show resolved Hide resolved
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
jcfranco marked this conversation as resolved.
Show resolved Hide resolved
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