Skip to content
Merged
Show file tree
Hide file tree
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
64 changes: 33 additions & 31 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

ensure_types_are_up_to_date() {
types_path="packages/calcite-components/src/components.d.ts"

if [ -n "$(git diff --name-only -- "$types_path")" ]; then
echo "Automatically staging changes to \"$types_path\""
git add "$types_path"
git add "$types_path" >/dev/null 2>&1 || true
fi
}

update_stylelint_config_if_sass_file_edited() {
staged_files="$(git diff --cached --name-only --diff-filter=ACM)"
staged_files="$(
git diff --cached --name-only --diff-filter=ACM -- packages/**/*.scss
)"

for file in $staged_files; do
if [[ "$file" == *.scss ]]; then
npm run util:update-stylelint-custom-sass-functions
break
fi
done

if [ -n "$(git diff --name-only -- "packages/calcite-components/.stylelintrc.json")" ]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤦‍♂️ Thanks for fixing this one.

git add "packages/calcite-components/.stylelintrc.json"
if [ -n "$staged_files" ]; then
npm run util:update-stylelint-custom-sass-functions
git add "packages/calcite-components/.stylelintrc.cjs" >/dev/null 2>&1 || true
fi

unset staged_files
}

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)"
staged_files="$(
git diff --cached --name-only --diff-filter=ACM -- packages/calcite-ui-icons/icons/*.svg
)"

for file in $staged_files; do
if [[ "$file" == "$svg_icon_dir"* ]]; then
if [[ "$file" == *.svg ]]; then
filename="$(basename "$file")"
if [ -n "$staged_files" ]; then
for file in $staged_files; do
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
# first, ensure the filename follows the valid pattern
if ! echo "$filename" | grep -qE "$valid_pattern"; then
printf "%s\n%s" \
"error: file '$file' does not follow the naming convention:" \
"(<iconname>-<size>.svg | <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
# then, ensure there's no invalid use of "-f-" anywhere except right before the size
if echo "$filename" | grep -qE "$invalid_pattern"; then
printf '%s\n%s' \
"error: file '$file' has an invalid '-f-' and does not follow the naming convention:" \
"(<iconname>-<size>.svg | <iconname>-<size>-f.svg)"
exit 1
fi
fi
done
done
fi

unset staged_files
}

lint-staged
Expand Down
32 changes: 19 additions & 13 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/usr/bin/env bash
# from https://riptutorial.com/git/example/16164/pre-push

protected_branch="main"
current_branch=$(git rev-parse --abbrev-ref HEAD)

if [ "$protected_branch" = "$current_branch" ] && bash -c ': >/dev/tty'; then
read -p "You're about to push main, is that what you intended? [y|n] " -n 1 -r </dev/tty
echo
if echo "$REPLY" | grep -E "^[Yy]$" >/dev/null; then
exit 0
fi
exit 1
#!/usr/bin/env sh

if ! bash -c ': >/dev/tty'; then
exit 0
fi

current_branch="$(git rev-parse --abbrev-ref HEAD)"

case "$current_branch" in
dev | main | rc)
printf "You're about to push a protected branch, is that what you intended? [y|n] "
read -r response

case "$response" in
y | Y) exit 0 ;;
*) exit 1 ;;
esac
;;
*) exit 0 ;;
esac
2 changes: 1 addition & 1 deletion support/updateStylelintCustomSassFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function collectSassFiles(dir: string): string[] {

try {
fs.readdirSync(dir, { recursive: true, withFileTypes: true }).forEach(dirent => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we need to recursively check files starting in the root directory or can we be more specific?

The only relevant directories are packages/calcite-components/src and packages/calcite-design-system/dist/scss right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the suggestion to narrow the search scope mainly for performance reasons? I’d like to avoid an allowlist, so we don’t need to (remember to) update this script if our Sass file directories change.

const fullPath = path.join(dir, dirent.name);
const fullPath = path.join(dirent.parentPath, dirent.name);

if (dirent.isFile() && fullPath.endsWith('.scss')) {
sassFiles.push(fullPath);
Expand Down